Repository navigation
Access properties directly from the entity #508
Description
Activity
- addedapi: datastoreIssues related to the Datastore API.Issues related to the Datastore API.
on Apr 21, 2015 Seems our entities are comprised of
keyanddataproperties, so that the user can access their key value by goingentity.keyinstead ofentity.__key__I believe. I'd suspect we'd have to change that if we wanted all the properties to be on the first level of the entity object like you described. Unless we wanted to potentially clobberentity.keybut I believekeyis not a reserved value as far as datastore is concerned, only__key__is reserved.I think the issue comes specifically because Javascript doesn't allow you to differentiate between a method (
entity.key()), a property (entity.key), and an attribute (entity['key']) -- as far as JS is concerned, it's all the same thing.One option would be to add a getter method for the key (
entity.getKey()) as a shortcut for the__key__attribute.This doesn't address the issue where things could be blasted out (ie,
getKeyas a property in Datastore would be blasted out by thegetKeymethod), so if we do something like this we'd need to also expose the "raw data" on the entity object as well.In short though, I think the common case will be "very few people will have a property called
getKey" -- we should optimize for that and allow people "go the long way" (ie,entity.data.getKey) if they are uncommon enough to name a property as that. (Note that apparently property names are allowed to have spaces -- and even start with spaces -- so there will be edge cases that we should make possible but not easy.)@ryanseys What do you think?
This sounds like a job well-suited for Proxies! Unfortunately Node doesn't universally support those. I think we might be able to get around this by attaching a special getter and setter to the
getKeyproperty of the entity object that detects when it's reassigned, and properly diverts the reassignment to the underlying property... I'll see what I can think up.Gave this a shot using a Symbol as a key: #1682
- added a commit that references this issue
on Sep 15, 2022 33 remaining items
- added a commit that references this issue
on Feb 2, 2026 - added a commit that references this issue
on Feb 3, 2026 - added a commit that references this issue
on Feb 3, 2026 - added a commit that references this issue
on Feb 4, 2026 - added a commit that references this issue
on Feb 5, 2026 - added a commit that references this issue
on Feb 26, 2026 - added a commit that references this issue
on Mar 5, 2026 - added a commit that references this issue
on Mar 5, 2026
When modifying or accessing entity properties, consistently you have to step into the data property:
Compare this to the other gcloud datastore APIs:
Python:
Ruby:
It would be nice if properties could be accessed on the entity directly.