GCP:获取主键字段以及数据存储中的其他字段

GCP: Fetch the primary key field along with other fields in Datastore

我想从数据存储类型中获取所有列。

datastore fields

#To get all books(all entity) from the datastore
@app.route("/getbookdetails", methods=['GET'])
  def getbookdetails():
  query=client.query(kind='tableofbooks')
  results = list(query.fetch())
  return json.dumps(results)

目前得到以下响应作为输出,但我想获取数据存储中也存在的 id 作为主键

[
    {
        "author": "new author",
        "description": "Google Datastore",
        "title": "sample insert",
        "yearofpublication": 2021
    }]

我用下面的代码解决了这个问题。

query=client.query(kind='tableofbooks')
        mylist=query.fetch()
        bookarray=[]
        for x in mylist:
            thisdict ={
                 "id":x.id,
                 "author":x['author'],
                 "description":x['description'],
                 "title":x['title'],
                 "yearofpublication":x['yearofpublication'],
            }
            bookarray.append(thisdict)
        return json.dumps(bookarray)