Giter Site home page Giter Site logo

Comments (6)

silvolu avatar silvolu commented on July 26, 2024

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.

jgeewax avatar jgeewax commented on July 26, 2024

/cc @GoogleCloudPlatform/cloud-datastore

from google-cloud-ruby.

pcostell avatar pcostell commented on July 26, 2024

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.

blowmage avatar blowmage commented on July 26, 2024

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.

jgeewax avatar jgeewax commented on July 26, 2024

👍 from me.

from google-cloud-ruby.

blowmage avatar blowmage commented on July 26, 2024

Please see #62.

from google-cloud-ruby.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.