使用 Python 在 Google Cloud Datastore 中保存实体:最小示例
以下是使用 Python API 在 Google Cloud Datastore 对象数据库中插入实体的最小示例:
datastore_save_example.py
#!/usr/bin/env python3
from google.cloud import datastore
# 创建并存储实体
client = datastore.Client(project="myproject-12345")
entity = datastore.Entity(key=client.key('MyEntityKind', 'MyTestID'))
entity.update({
'foo': u'bar',
'baz': 1337,
'qux': False,
})
# 实际保存实体
client.put(entity)这假设你已经在 ID 为 myproject-12345 的项目中创建了名为 MyEntityKind 的实体种类。
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow