https://developers.google.com/appengine/docs/python/ndb/
https://developers.google.com/appengine/docs/python/ndb/queries
ndb.gql 和 ndb.query 之间有区别吗?(除了语法)
例如
cursor = ndb.gql("select * from Account")
对比
cursor = Account.query()
因为我喜欢 ndb.query 因为我认为它更具可读性
例子:
acc=Account.query(Account.username==form.username.data,Account.password==form.password.data)
如果这两种方法在后台不同/相等,我找不到任何信息。
=> 也许有一个性能权衡?
如果您习惯使用 SQL,请在使用 GQL 时注意错误假设。GQL 被翻译成 NDB 的原生查询 API。这不同于典型的对象关系映射器(如 SQLAlchemy 或 Django 的数据库支持),其中 API 调用在传输到数据库服务器之前被转换为 SQL。GQL 不支持 Datastore 修改(插入、删除或更新);它只支持查询。
我猜 ndb.query 应该“更快”,因为它不需要翻译对吗?