Comments (6)
Agree with you we should be permissive, unless we do something like registering kinds (as proposed in googleapis/google-cloud-node#157), and then we'd want to enforce a schema.
That proposal is currently blocked on the feature being implemented in the API itself.
from google-cloud-ruby.
/cc @GoogleCloudPlatform/cloud-datastore
from google-cloud-ruby.
The next version of the API will have an explicit null value. So something to consider is that if entity[...] returns nil, there will be no way to distinguish between a set null value and a missing value.
from google-cloud-ruby.
For the past month or so I've been thinking about differentiating between and entity not having a property vs. having a property with a NULL value. Closely related is how to remove a property from an entity vs. setting the property's value to NULL. First, a bit of background. Currently the Entity has a properties
method that returns an array of arrays of the properties and values. But this is a read-only list, and modifications aren't possible.
entity["name"] = "Mike"
entity["email"] = "[email protected]"
entity.properties #=> [["name", "Mike"], ["email", "[email protected]"]]
entity.properties.clear #=> []
entity.properties #=> [["name", "Mike"], ["email", "[email protected]"]]
I'd like to change properties
to return a hash-like object that can be inspected and modified:
entity["name"] = "Mike"
entity["email"] = "[email protected]"
entity.properties #=> {"name" => "Mike", "email" => "[email protected]"}
# Check for a property that exists
entity.properties.exist? "name" #=> true
entity["name"] #=> "Mike"
entity.properties["name"] #=> "Mike"
# Check for a property that does not exist
entity.properties.exist? "age" #=> false
entity["age"] #=> nil
entity.properties["age"] #=> nil
# Deleting a property
entity.properties.exist? "email" #=> true
entity.properties.delete "email"
entity.properties.exist? "email" #=> false
entity.properties #=> {"name" => "Mike"}
Here is the my proposed API for this new property object:
PropertyStore#[] key
PropertyStore#[]= key, value
PropertyStore#read key
PropertyStore#write key, value
PropertyStore#exist? key
PropertyStore#fetch key, &block
PropertyStore#delete key, &block
PropertyStore#each
This object would also be responsible for normalizing keys to make sure they were always stored as strings but could be accessed as symbols.
entity[:name] = "Mike"
entity[:email] = "[email protected]"
entity.properties.exist? :name #=> true
entity.properties.exist? "name" #=> true
entity.properties #=> {"name" => "Mike", "email" => "[email protected]"}
In the future I can also see this object being responsible for dirty tracking changes, so we don't have to update every property when saving an entity, only the properties that changed. This would be API-compatible with ActiveModel's dirty tracking. Thoughts?
from google-cloud-ruby.
👍 from me.
from google-cloud-ruby.
Please see #62.
from google-cloud-ruby.
Related Issues (20)
- [Nightly CI Failures] Failures detected for google-cloud-storage HOT 1
- [Nightly CI Failures] Failures detected for google-cloud-errors HOT 7
- [Nightly CI Failures] Failures detected for google-cloud-core HOT 7
- NoMethodError: undefined method `is_a?' for <Config HOT 3
- storage: add object retention samples
- [Nightly CI Failures] Failures detected for google-cloud-recommender HOT 2
- [Nightly CI Failures] Failures detected for google-cloud-recommender-v1 HOT 2
- [Nightly CI Failures] Failures detected for google-cloud-vision-v1 HOT 3
- [Nightly CI Failures] Failures detected for google-cloud-vision-v1p4beta1 HOT 3
- [Nightly CI Failures] Failures detected for google-cloud-vision-v1p3beta1 HOT 3
- undefined method `is_a?` for <Config...>:Google::Cloud::Config> rescued during inspection HOT 1
- Dependency Conflict with faraday in `google-cloud-translate-v2` HOT 1
- google-cloud-recaptcha_enterprise Needs Latest Version of google-auth-library-ruby HOT 1
- `Encoding::UndefinedConversionError` when downloading content to a file
- [Nightly CI Failures] Failures detected for google-cloud-vision-v1p4beta1 HOT 1
- [Nightly CI Failures] Failures detected for google-cloud-vision-v1p3beta1 HOT 1
- [Nightly CI Failures] Failures detected for google-cloud-vision-v1 HOT 1
- [Nightly CI Failures] Failures detected for google-cloud-pubsub HOT 1
- Firestore & Datastore PRs are failing due to aggregates feature HOT 2
- [Nightly CI Failures] Failures detected for google-cloud-bigquery-migration-v2 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from google-cloud-ruby.