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

transaction.get() is undocumented and buggy #783

Open
kaansoral opened this issue Jan 22, 2021 · 2 comments
Open

transaction.get() is undocumented and buggy #783

kaansoral opened this issue Jan 22, 2021 · 2 comments
Labels
api: datastore Issues related to the googleapis/nodejs-datastore API. type: cleanup An internal cleanup or hygiene concern. type: docs Improvement to the documentation for an API.

Comments

@kaansoral
Copy link

kaansoral commented Jan 22, 2021

  1. I can't see .get() documented here: https://googleapis.dev/nodejs/datastore/latest/Transaction.html
  2. Like all annoying Node.js methods, even if you provide a single key to it, it returns an array with that entity
  3. It seems to work if you provide an array of keys to it, but instead of returning an array of entities, it returns an array of an array that have the first entity in it's 0th slot (This is a bug, it shouldn't work at all)

Some bonus questions to whoever designed this entire API:

  1. Why datastore.key(['Kind',key]) instead of datastore.key('Kind',key)
  2. For the regular datastore.get (and this one too), providing a single key returns an array including that single element, can you sleep at night?

Coming from a Python NDB background, I really don't understand these decisions, even from a JS standpoint, they don't make sense

@product-auto-label product-auto-label bot added the api: datastore Issues related to the googleapis/nodejs-datastore API. label Jan 22, 2021
@kaansoral
Copy link
Author

I mean, since transaction.get() doesn't accept an array of keys like datastore.get() - it should've at least returned a single bare entity, but it also returns a 1 Length array with the entity inside - I mean it just doesn't make any sense ...

@stephenplusplus
Copy link
Contributor

I can't see .get() documented here: https://googleapis.dev/nodejs/datastore/latest/Transaction.html

@AVaksman do you know how to get that method in there?

if you provide a single key to [transaction.get()], it returns an array with that entity
providing a single key returns an array including that single element
it should've at least returned a single bare entity, but it also returns a 1 Length array with the entity inside
It seems to work if you provide an array of keys to it, but instead of returning an array of entities, it returns an array of an array

@AVaksman Is promisifyAll forcing the array / is it possible to work around it?

transaction.get() doesn't accept an array of keys like datastore.get()

It seemed to accept two keys and return both matching entities in my testing:

const key = datastore.key(['Company', 'Google']);
const key2 = datastore.key(['Company', 'Google2']);

datastore.save({key, data: {url: 'www.google.com'}});
datastore.save({key: key2, data: {url: 'www.google.com'}});

const transaction = datastore.transaction();
await transaction.run();

const [entities] = await transaction.get([key, key2]);
console.log(entities[0]); // { url: 'www.google.com', [Symbol(KEY)]: [Key] }
console.log(entities[1]); // { url: 'www.google.com', [Symbol(KEY)]: [Key] }

Why datastore.key(['Kind',key]) instead of datastore.key('Kind',key)

We could probably add support for that style of usage. Are you interested in sending a PR?

@stephenplusplus stephenplusplus added the type: docs Improvement to the documentation for an API. label Jan 22, 2021
@kolea2 kolea2 added the type: cleanup An internal cleanup or hygiene concern. label Feb 13, 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 googleapis/nodejs-datastore API. type: cleanup An internal cleanup or hygiene concern. type: docs Improvement to the documentation for an API.
Projects
None yet
Development

No branches or pull requests

3 participants