Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google app engine 如何用查询替换gql类型的查询?_Google App Engine_Google Cloud Datastore - Fatal编程技术网

Google app engine 如何用查询替换gql类型的查询?

Google app engine 如何用查询替换gql类型的查询?,google-app-engine,google-cloud-datastore,Google App Engine,Google Cloud Datastore,我有以下代码,运行良好: comments = PersonComment.gql('WHERE ANCESTOR IS :parent AND verified=True ORDER BY added DESC', parent=person_key).fetch(PAGE_SIZE_COMMENTS+1, (page)*PAGE_SIZE_COMMENTS) 我想用以下内容来代替: comments = db.Query(PersonComment) comments.ancest

我有以下代码,运行良好:

comments = PersonComment.gql('WHERE ANCESTOR IS :parent AND verified=True ORDER BY added DESC', parent=person_key).fetch(PAGE_SIZE_COMMENTS+1, (page)*PAGE_SIZE_COMMENTS)
我想用以下内容来代替:

  comments = db.Query(PersonComment)
  comments.ancestor(person_key)
  comments.filter('verified = ', True)
  comments.order('-added')
  comments.fetch(PAGE_SIZE_COMMENTS+1, (page)*PAGE_SIZE_COMMENTS)

但它不起作用。有什么问题吗?

fetch
返回一个结果集<代码>注释仍然是一个查询对象。您可以这样做:

comments=comments.fetch(页面大小\u comments+1,(页面)*页面大小\u comments)

或者将查询对象称为其他对象以避免混淆


另一方面,使用带有偏移量的fetch进行分页确实效率低下。考虑使用.< /P> < P> <代码> FETCH < /COD>返回结果集;代码>注释仍然是一个查询对象。您可以这样做:

comments=comments.fetch(页面大小\u comments+1,(页面)*页面大小\u comments)

或者将查询对象称为其他对象以避免混淆


另一方面,使用带有偏移量的fetch进行分页确实效率低下。考虑使用.< /P>谢谢,Drew。fetch是否真的读取了所有记录并返回了我所请求的内容(与游标相比)?为什么我要使用游标?@LA_uu摆脱带有偏移量的查询,并按照建议使用游标。带有偏移量的查询效率很低,而且从计费角度来看,需要花费大量的数据存储读取。谢谢,Drew。fetch是否真的读取了所有记录并返回了我所请求的内容(与游标相比)?为什么我要使用游标?@LA_uu摆脱带有偏移量的查询,并按照建议使用游标。带有偏移量的查询效率很低,而且从计费角度来看,需要花费大量的数据存储读取。