Code Monkey home page Code Monkey logo

Comments (10)

pwhelan avatar pwhelan commented on May 23, 2024

I am tackling a few issues right now. If you have any documentation you refer to for ancestor queries that would be great.

from datachore.

hilnius avatar hilnius commented on May 23, 2024

For documentation, I'd say https://cloud.google.com/datastore/docs/apis/overview and https://github.com/google/google-api-php-client

from datachore.

pwhelan avatar pwhelan commented on May 23, 2024

I found nothing there documenting ancestors specifically but I did find it here: https://cloud.google.com/datastore/docs/concepts/entities#Datastore_Ancestor_paths. This is possible but will take quite a bit of a rewrite since it looks like it has to be written right into the record's key (analogous to the primary key in an SQL table but quite a bit more complex).

from datachore.

pwhelan avatar pwhelan commented on May 23, 2024

The thing I still cannot wrap my head around is how a child is related to the parent in the actual data structure.

AFAICT it works like this:

Entity #1 (parent) key:
    path[0]:
        kind: Person
        name: Martin Sheen

Entity #2 (child) key:
    path[0]:
        kind: Person
        name: Martin Sheen
    path[1]:
        kind: Person
        name: Charlie Sheen

And then the Data store will automatically assign the ID's and relate Martin Sheen's actually entity to Charlie Sheen's for us?

from datachore.

hilnius avatar hilnius commented on May 23, 2024

If you look at the API here : https://cloud.google.com/datastore/docs/apis/v1beta2/key is how a key is implemented (in JSON) and here : https://cloud.google.com/datastore/docs/apis/v1beta2/datasets/commit there is the full doc on inserting entities. As explained, when you insert an entity, you specify (in your case)

"key": {
  "partitionId": {
    "datasetId": string,
    "namespace": string
  },
  "path": [
    { // this entity is Martin Sheen
      "kind": "Person",
      "id": "1"
    },
    { // this is Charlie Sheen
      "kind": "Person",
      "id": "2"
      // I think you can also specify a name here if you don't want numeric ids but string keys
    }
  ]
},
"properties": {
  "name": {
    "stringValue": "Charlie Sheen"
  },
}

This is probably (not tested) what a query that inserts a "Person", "Charlie Seen" in your DB, with an ancestor path putting Charlie as a son of Martin.

I haven't tried those json structures with the api, but I think the best way to understand how those queries perform is to use the "try it" part of the api doc pages.

Don't believe all I say, as I've never used the datastore, I've just read the docs a lot.

from datachore.

pwhelan avatar pwhelan commented on May 23, 2024

Setting both the name and the id on path element (the members of the path array property) raises an error, which is where things started to confuse me.

Fatal error: Uncaught exception 'google\appengine\runtime\ApplicationError' 
with message 'Key path element has both id (5804871638843392) and name ("prev").' 
in google_appengine/php/sdk/google/appengine/runtime/RemoteApiProxy.php:84

from datachore.

hilnius avatar hilnius commented on May 23, 2024

Yeah. An entity is identifiable either by a numeric "id" OR by a "name" string, but not both.
It's like in SQL using a VARCHAR primary key UR an INTEGER primary key. You cannot have two primary keys. If you wanna use numeric ids, you can use the "id" field, and if you want to use string identifiers, you can use "name".

from datachore.

pwhelan avatar pwhelan commented on May 23, 2024

I just pushed a branch called ancestors which has support for saving entities ancestor keys.

TODO

  • add support for querying entities with ancestors
  • automatically add indexes for ancestor queries to index.yaml via the autoindexer.
  • add tests.

You should be able to pull in the ancestor branch via composer by requiring the version: 'dev-ancestor'.

{
    "require": {
        "datachore/datachore": "dev-ancestor"
    }
}

from datachore.

hilnius avatar hilnius commented on May 23, 2024

Cool. I'll check it when I got some time. Thanks a lot !

from datachore.

pwhelan avatar pwhelan commented on May 23, 2024

The tests are failing in that branch at the moment. I'll fix it soon, PR's are highly appreciated though.

from datachore.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.