My latest frustration: https://github.com/googleapis/nodejs-datastore/issues/783
Undocumented transaction.get() and unexpected behaviour On Tuesday, January 12, 2021 at 5:47:39 PM UTC+3 Elliott (Cloud Platform Support) wrote: > Hello, > > Thank you for your question. I understand correctly, you would like to > point out that there is a differing programming style between the two > documents and you would like clarification on the examples provided. > > The best way to move forward is to create an issue on Github here > <https://github.com/googleapis/nodejs-datastore/issues> that will be > addressed by the specialists. They deal with questions like yours and may > guide you. I understand your frustration on this. > > > > > > On Tuesday, January 12, 2021 at 7:21:13 AM UTC-5 [email protected] wrote: > >> I have to say the NodeJS Datastore methods is really not well thought, at >> all - they are almost sadistic in nature >> >> .get() doesn't have a sync option, which is perfectly okay at this point >> in time, almost all functions need to be async, might as well await >> >> However, what is not okay is that, it returns an array with only one >> entity, even if you provide a single key to it >> >> So you always have to: >> ``` >> var entity=await datastore.get(datastore.key(["Name","key"])); >> if(entity) entity=entity[0]; >> ``` >> >> The natural response is to return a singular entity, not an array with >> one entity >> All the Python API's up to this point has been like this too, so the >> expected response is this also >> >> At every point, I stop and ask >> >> [image: giphy.gif] >> >> On Sunday, January 10, 2021 at 9:20:02 PM UTC+3 Kaan wrote: >> >>> Another confusing matter, do we .rollback() explicitly, even if the >>> exception is from the .commit() - I guess so - honestly they all make up a >>> huge code mess, it could've been simpler if the transaction routines were >>> actually transaction routines and these were automated? I guess one could >>> also easily write wrappers that do this >>> >>> So my point is, I guess it's not a transaction system exactly, but more >>> like a lock, lock-check, lock-release system - correct me if I missed >>> anything >>> >>> On Sunday, January 10, 2021 at 9:12:21 PM UTC+3 Kaan wrote: >>> >>>> The docs here use .run() - more like a .start()-like command: >>>> https://cloud.google.com/datastore/docs/concepts/transactions >>>> >>>> However the direct reference: >>>> https://googleapis.dev/nodejs/datastore/latest/Transaction.html#run >>>> >>>> Uses .run(function(){ DO_THINGS_HERE_THEN_COMMIT }); kinda way >>>> >>>> So basically the App Engine examples use .run() like a formality, they >>>> just call transaction's get methods etc. afterwards - but the direct docs >>>> suggest everything to be inside .run() >>>> >>>> *Question:* I'm guessing .run() is like a formality that starts a >>>> transaction, the transaction.get()'s etc. lock entities, and if they are >>>> modified outside, transaction fails? - so basically, instead of a >>>> formality >>>> .run() - the other transaction commands could've internally done this too >>>> >>>> And I also guess retries aren't a thing any more, so using .run() like >>>> a formality goes - however, if the default approach was to put everything >>>> inside the run()'s callback function, couldn't there be a retry parameter >>>> too? >>>> >>> -- You received this message because you are subscribed to the Google Groups "Google App Engine" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/google-appengine/b2b5cc57-445a-4892-86b2-ba91155217f4n%40googlegroups.com.
