GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — datastore: runQuery should return complete objects rather than objects and keys · Issue #38 · googleapis/google-cloud-node

datastore: runQuery should return complete objects rather than objects and keys #38

New issue
Copy link
New issue
Copy link
Closed
Closed
datastore: runQuery should return complete objects rather than objects and keys#38
Copy link
Assignees
rakyll
Labels
🚨This issue needs some love.api: datastoreIssues related to the Datastore API.triage meI really want to be triaged.
Milestone
Datastore Stable

Description

@jasonpolites
jasonpolites
opened on Jul 28, 2014
Issue body actions

The callback for runQuery returns keys and objects as separate collections:

https://github.com/GoogleCloudPlatform/gcloud-node#querying

This is a little problematic if you want to return "whole" objects back to the client. Perhaps this is a Datatstore specific thing, but in almost all cases the client will want the key in the object. Do I have to iterate the collections and re-constitute the object by inserting a "key" (or "id") property?

E.g what I want on the client is something like this:

{
    "_id" : 5654313976201216,
    "foo" : "bar"
}

what I get is:

{
    "foo" : "bar"
}

with the ID/key in a separate (symmetrical) collection.

Activity

Next
  1. jgeewax
    added
    bug
    on Jul 28, 2014
  2. jasonpolites commented on Jul 28, 2014

    @jasonpolites
    jasonpolites
    on Jul 28, 2014
    Author
    More actions

    This also applies to get.

  3. rakyll
    added
    0.1.x
    and removed
    0.1.x
    on Jul 28, 2014
  4. rakyll commented on Jul 28, 2014

    @rakyll
    rakyll
    on Jul 28, 2014
    Contributor
    More actions

    This is a little problematic if you want to return "whole" objects back to the client. Perhaps this is a Datatstore specific thing, but in almost all cases the client will want the key in the object. Do I have to iterate the collections and re-constitute the object by inserting a "key" (or "id") property?

    Why do you need to reconstruct the object with its identifier? The client applies the separation of keys and objects everywhere.

    Not embedding keys allows users to work with plain objects. Yes, you need two declarations, but it's much easier than having model definitions and constructing an instance from your model definitions.

  5. rakyll
    changed the title [-]runQuery should return complete objects rather than objects and keys[/-] [+]datastore: runQuery should return complete objects rather than objects and keys[/+] on Jul 28, 2014
  6. jasonpolites commented on Jul 28, 2014

    @jasonpolites
    jasonpolites
    on Jul 28, 2014
    Author
    More actions

    It's just an issue of simplicity. In 99% of cases the use case will require the id/key at the same time the object is required. Having separate collections just means the developer has to index into the key collection for every item in the object collection. It's just more code to write/test etc.

    It also means that when the developer wants to update that object, they need to either internalize the key themselves, or keep a reference to it somewhere else. Again, more code and more chance of bugs.

    The "plain objects" argument applies less to dynamic languages like JS IMO. If collision with existing named properties is a concern, then adding the ability to set the name of the "key" field would work but honestly most developers are familiar with the "_id" syntax (from mongodb).

  7. rakyll commented on Jul 29, 2014

    @rakyll
    rakyll
    on Jul 29, 2014
    Contributor
    More actions

    As long as we provide a setting to override the key of the identifier, +1 to _id. @proppy, any comments/concerns?

  8. rakyll
    added this to the This milestone has been deleted milestone on Jul 29, 2014
  9. proppy commented on Jul 30, 2014

    @proppy
    proppy
    on Jul 30, 2014
    Contributor
    More actions

    Yes, to me clashing with the namespace of the property names is a concern, you can't assume no existing App Engine app have an existing entities w/ _id properties, you never know.

    IIRC a few property name are reserved (@pcostell could correct me if I'm wrong), for example: __key__ pseudo property could be a good fit here.

    Another option is not have a compound entity object closer to the existing Cloud Datastore API entity payload

    {
       "key": [ "Kind", "name", "Kind", 42],
       "properties": {
            "name": "value"
       }
    }
    
  10. pcostell commented on Jul 30, 2014

    @pcostell
    pcostell
    on Jul 30, 2014
    Contributor
    More actions

    If you want to expose key as a property, you should do so via __key__. This is also consistent with how the user would provide it in a projection SELECT __key__ FROM ..... I don't think you want to expose just the id, as keys can have names or ids and the ancestor / Kind can be important.

  11. rakyll commented on Jul 30, 2014

    @rakyll
    rakyll
    on Jul 30, 2014
    Contributor
    More actions

    you can't assume no existing App Engine app have an existing entities w/ _id properties, you never know.

    Actually, it's more likely that existing entities have an _id field due to its popularity.

    If you want to expose key as a property, you should do so via key.

    __key__ is an obvious option, but in terms of code readability, I think it's ugly and you shouldn't be supposed to touch a key with an underscore from an external module.

    We don't support GQL yet, I'll make sure we're consistent if we do.

    I don't think you want to expose just the id, as keys can have names or ids and the ancestor / Kind can be important.

    Yes, key is a list of kinds and numeric or string identifiers with optional namespace. So a gcloud-node key is literally a Key [1].

    [1] https://github.com/GoogleCloudPlatform/gcloud-golang/blob/master/internal/datastore/datastore_v1.proto#L50

  12. stephenplusplus commented on Jul 30, 2014

    @stephenplusplus
    stephenplusplus
    on Jul 30, 2014
    Contributor
    More actions
    {
       "key": [ "Kind", "name", "Kind", 42],
       "properties": {
            "name": "value"
       }
    }

    - @proppy

    As a dev using this lib, I would prefer exactly this. Explicit and concise, without a chance of collisions.

    To confirm:

    datastore.runQuery({/*...*/}, function (err, entities, nextQuery) {
      /*
        entities = [
          {
            key: ['Kind', 'name', 'Kind', 42],
            properties: {
              name: 'value'
            }
          },
          // {},
          // {}
        ]
      */
    });

    @jasonpolites wdyt?

  13. 112 remaining items

  14. sofisl
    added 3 commits that reference this issue on Mar 5, 2026

    chore: Retry request migration (#858)

    6dcb8a6

    chore: lock files maintenance (#38)

    639c6e2

    chore(deps): update dependency @types/nock to v10 (#38)

    f5d5e33
  15. GautamSharda
    added 2 commits that reference this issue on Mar 11, 2026

    Fix JSDoc and regenerate scaffolding. (#39)

    5a5a44c

    Update google-proto-files to the latest version 🚀 (#139)

    de1f7c5
  16. codyoss
    added a commit that references this issue on Mar 12, 2026

    build: ignore proto files in test coverage (#38)

    58ffd21
  17. GautamSharda
    added 3 commits that reference this issue on Mar 12, 2026

    chore: update new issue template (#38)

    b17996d

    chore: update new issue template (#38)

    06fba30

    chore: removing node7 job from CircleCI (#38)

    c812fb5
  18. thiyaguk09
    added a commit that references this issue on Mar 18, 2026

    PubSub Notifications (#38)

    2e7e278
  19. GautamSharda
    added 2 commits that reference this issue on Mar 23, 2026

    Update @google-cloud/common to the latest version 🚀 (#38)

    5f78cd4

    Update @google-cloud/common to the latest version 🚀 (#38)

    53feb99
  20. feywind
    added 2 commits that reference this issue on Mar 27, 2026

    Fix JSDoc and regenerate scaffolding. (#39)

    0fbf3ce

    Update google-proto-files to the latest version 🚀 (#139)

    90b0034
  21. shivanee-p
    added a commit that references this issue on Mar 27, 2026

    Update @google-cloud/common to the latest version 🚀 (#38)

    3f8620e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @rakyll
    rakyll

Labels

🚨This issue needs some love.api: datastoreIssues related to the Datastore API.triage meI really want to be triaged.

Type

No type

Projects

No projects

    Milestone

    • Datastore Stable

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.