Google DataStore - createdAt 属性和更新
Google DataStore - createdAt attribute and updates
了解条目/文档何时创建通常非常有用。但是由于不可能只更新 Google DataStore 中的一组特定属性,因此很难在对象的整个生命周期内保持 createdAt 的值。
从本质上讲,为了让 DataStore 具有 createdAt 属性,应用程序必须 [get] 条目以检索 createdAt 值,然后 [update] 它重新使用该值。当然,这意味着更多 $$$,因为每次更新都会发出 2 API 个请求,而不是 1 个。
我是否遗漏了什么,或者这是解决此问题的最佳方法吗?
是否支持此类功能取决于您使用的客户端库。
例如 ndb
client library recommended for the 1st generation App Engine applications offers such support. From Date and Time Properties:
Each of these properties has two extra Boolean keyword options:
auto_now_add
Set property to current date/time when entity is created. You can
manually override this property. When the entity is updated, the
property doesn't change. For that behavior, use auto_now.
auto_now
Set property to current date/time when entity is created and whenever
it is updated.
因此,当您 put
将实体放入数据存储区而没有为此类属性提供值(并且它们已设置这些选项)时,它们会自动更新。
了解条目/文档何时创建通常非常有用。但是由于不可能只更新 Google DataStore 中的一组特定属性,因此很难在对象的整个生命周期内保持 createdAt 的值。
从本质上讲,为了让 DataStore 具有 createdAt 属性,应用程序必须 [get] 条目以检索 createdAt 值,然后 [update] 它重新使用该值。当然,这意味着更多 $$$,因为每次更新都会发出 2 API 个请求,而不是 1 个。
我是否遗漏了什么,或者这是解决此问题的最佳方法吗?
是否支持此类功能取决于您使用的客户端库。
例如 ndb
client library recommended for the 1st generation App Engine applications offers such support. From Date and Time Properties:
Each of these properties has two extra Boolean keyword options:
auto_now_add
Set property to current date/time when entity is created. You can manually override this property. When the entity is updated, the property doesn't change. For that behavior, use auto_now.
auto_now
Set property to current date/time when entity is created and whenever it is updated.
因此,当您 put
将实体放入数据存储区而没有为此类属性提供值(并且它们已设置这些选项)时,它们会自动更新。