Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jasonpolites opened this issue Jul 28, 2014 · 13 comments
Assignees
Labels
api: datastore Issues related to the Datastore API. 🚨 This issue needs some love. triage me I really want to be triaged.

Comments

@jasonpolites
Copy link

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.

@jasonpolites
Copy link
Author

This also applies to get.

@rakyll rakyll added 0.1.x and removed 0.1.x labels Jul 28, 2014
@rakyll
Copy link
Contributor

rakyll commented Jul 28, 2014

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.

@rakyll 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 Jul 28, 2014
@jasonpolites
Copy link
Author

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).

@rakyll
Copy link
Contributor

rakyll commented Jul 29, 2014

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

@rakyll rakyll added this to the M1: core, datastore & storage milestone Jul 29, 2014
@proppy
Copy link
Contributor

proppy commented Jul 30, 2014

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"
   }
}

@pcostell
Copy link
Contributor

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.

@rakyll
Copy link
Contributor

rakyll commented Jul 30, 2014

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

@stephenplusplus
Copy link
Contributor

{
   "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?

@jasonpolites
Copy link
Author

I think that's fine, although the key structure is not going to be familiar to developers not familiar with datastore. Also is the second 'Kind' actually the namespace? Or the parent kind?

Assuming I can just throw the value for key into a separate call without needing to parse out any of its constituents then LGTM.

Can we copy/paste some language about key structure into the Entities & Keys section of the README? Perhaps from here?

@rakyll rakyll modified the milestones: M1: core, datastore & storage, M2 Jul 31, 2014
stephenplusplus added a commit to stephenplusplus/gcloud-node that referenced this issue Jul 31, 2014
@rakyll
Copy link
Contributor

rakyll commented Jul 31, 2014

Also is the second 'Kind' actually the namespace? Or the parent kind?

Child kind.

@jasonpolites
Copy link
Author

Oh that's unexpected. So an entity with 100 children would have 100 entries in the key?

@rakyll
Copy link
Contributor

rakyll commented Aug 1, 2014

No, parent's key will be

['ParentKind', 'name']

and children keys will look like what's below.

['ParentKind', 'name', 'ChildKind', 42],
['ParentKind', 'name', 'ChildKind', 43],
['ParentKind', 'name', 'ChildKind', 44],
['ParentKind', 'name', 'ChildKind', 45]...

@jasonpolites
Copy link
Author

Ah. I see. Thanks.
On Jul 31, 2014 5:04 PM, "Burcu Dogan" [email protected] wrote:

No, parent's key will be

['ParentKind', 'name']

and children keys will look like what's below.

['ParentKind', 'name', 'ChildKind', 42],['ParentKind', 'name', 'ChildKind', 43],['ParentKind', 'name', 'ChildKind', 44],['ParentKind', 'name', 'ChildKind', 45]...


Reply to this email directly or view it on GitHub
#38 (comment)
.

@rakyll rakyll closed this as completed in 7197b6c Aug 1, 2014
rakyll pushed a commit that referenced this issue Aug 1, 2014
fixes #38 return key/prop combined object.
sofisl pushed a commit that referenced this issue Nov 11, 2022
sofisl pushed a commit that referenced this issue Nov 11, 2022
sofisl pushed a commit that referenced this issue Nov 11, 2022
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
sofisl added a commit that referenced this issue Nov 11, 2022
* fix(build): migrate to using main branch

* 🦉 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
sofisl pushed a commit that referenced this issue Nov 11, 2022
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Co-authored-by: Jeffrey Rennie <[email protected]>
sofisl added a commit that referenced this issue Nov 12, 2022
* build!: Update library to use Node 12
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
sofisl pushed a commit that referenced this issue Jan 10, 2023
sofisl pushed a commit that referenced this issue Jan 10, 2023
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [webpack-cli](https://togithub.com/webpack/webpack-cli/tree/master/packages/webpack-cli) ([source](https://togithub.com/webpack/webpack-cli)) | [`^4.0.0` -> `^5.0.0`](https://renovatebot.com/diffs/npm/webpack-cli/4.10.0/5.0.1) | [![age](https://badges.renovateapi.com/packages/npm/webpack-cli/5.0.1/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/webpack-cli/5.0.1/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/webpack-cli/5.0.1/compatibility-slim/4.10.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/webpack-cli/5.0.1/confidence-slim/4.10.0)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>webpack/webpack-cli</summary>

### [`v5.0.1`](https://togithub.com/webpack/webpack-cli/blob/HEAD/CHANGELOG.md#&#8203;501-httpsgithubcomwebpackwebpack-clicomparewebpack-cli500webpack-cli501-2022-12-05)

[Compare Source](https://togithub.com/webpack/webpack-cli/compare/[email protected]@5.0.1)

##### Bug Fixes

-   make `define-process-env-node-env` alias `node-env` ([#&#8203;3514](https://togithub.com/webpack/webpack-cli/issues/3514)) ([346a518](https://togithub.com/webpack/webpack-cli/commit/346a518dd7423a726810ef1012031f92d318c9c5))

### [`v5.0.0`](https://togithub.com/webpack/webpack-cli/blob/HEAD/CHANGELOG.md#&#8203;500-httpsgithubcomwebpackwebpack-clicomparewebpack-cli4100webpack-cli500-2022-11-17)

[Compare Source](https://togithub.com/webpack/webpack-cli/compare/[email protected]@5.0.0)

##### Bug Fixes

-   improve description of the `--disable-interpret` option ([#&#8203;3364](https://togithub.com/webpack/webpack-cli/issues/3364)) ([bdb7e20](https://togithub.com/webpack/webpack-cli/commit/bdb7e20a3fc5a676bf5ba9912c091a2c9b3a1cfd))
-   remove the redundant `utils` export ([#&#8203;3343](https://togithub.com/webpack/webpack-cli/issues/3343)) ([a9ce5d0](https://togithub.com/webpack/webpack-cli/commit/a9ce5d077f90492558e2d5c14841b3b5b85f1186))
-   respect `NODE_PATH` env variable ([#&#8203;3411](https://togithub.com/webpack/webpack-cli/issues/3411)) ([83d1f58](https://togithub.com/webpack/webpack-cli/commit/83d1f58fb52d9dcfa3499efb342dfc47d0cca73a))
-   show all CLI specific flags in the minimum help output ([#&#8203;3354](https://togithub.com/webpack/webpack-cli/issues/3354)) ([35843e8](https://togithub.com/webpack/webpack-cli/commit/35843e87c61fd27be92afce11bd66ebf4f9519ae))

##### Features

-   failOnWarnings option ([#&#8203;3317](https://togithub.com/webpack/webpack-cli/issues/3317)) ([c48c848](https://togithub.com/webpack/webpack-cli/commit/c48c848c6c84eb73fbd829dc41bee301b0b7e2de))
-   update commander to v9 ([#&#8203;3460](https://togithub.com/webpack/webpack-cli/issues/3460)) ([6621c02](https://togithub.com/webpack/webpack-cli/commit/6621c023ab59cc510a5f76e262f2c81676d1920b))
-   added the `--define-process-env-node-env` option
-   update `interpret` to v3 and `rechoir` to v0.8
-   add an option for preventing interpret ([#&#8203;3329](https://togithub.com/webpack/webpack-cli/issues/3329)) ([c737383](https://togithub.com/webpack/webpack-cli/commit/c7373832b96af499ad0813e07d114bdc927afdf4))

##### BREAKING CHANGES

-   the minimum supported webpack version is v5.0.0 ([#&#8203;3342](https://togithub.com/webpack/webpack-cli/issues/3342)) ([b1af0dc](https://togithub.com/webpack/webpack-cli/commit/b1af0dc7ebcdf746bc37889e4c1f978c65acc4a5)), closes [#&#8203;3342](https://togithub.com/webpack/webpack-cli/issues/3342)
-   webpack-cli no longer supports webpack v4, the minimum supported version is webpack v5.0.0
-   webpack-cli no longer supports webpack-dev-server v3, the minimum supported version is webpack-dev-server v4.0.0
-   remove the `migrate` command ([#&#8203;3291](https://togithub.com/webpack/webpack-cli/issues/3291)) ([56b43e4](https://togithub.com/webpack/webpack-cli/commit/56b43e4baf76c166ade3b282b40ad9d007cc52b6)), closes [#&#8203;3291](https://togithub.com/webpack/webpack-cli/issues/3291)
-   remove the `--prefetch` option in favor the `PrefetchPlugin` plugin
-   remove the `--node-env` option in favor `--define-process-env-node-env`
-   remove the `--hot` option in favor of directly using the `HotModuleReplacement` plugin (only for `build` command, for `serve` it will work)
-   the behavior logic of the `--entry` option has been changed - previously it replaced your entries, now the option adds a specified entry, if you want to return the previous behavior please use `  webpack --entry-reset --entry './src/my-entry.js' `

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 9am and before 3pm" (UTC), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/nodejs-run).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4yNi40IiwidXBkYXRlZEluVmVyIjoiMzQuMjQuMCJ9-->
sofisl pushed a commit that referenced this issue Jan 17, 2023
sofisl pushed a commit that referenced this issue Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: datastore Issues related to the Datastore API. 🚨 This issue needs some love. triage me I really want to be triaged.
Projects
None yet
Development

No branches or pull requests

7 participants