gql

How do I query for entities that are “nearby” with the GeoPt property in Google App Engine?

徘徊边缘 提交于 2019-11-29 14:34:42
问题 How should I create a GQL query that returns the nearest entities (from my current location) based on their GeoPt property? Should I just created a 'distance' function that calculates for a set of entities with a reasonably close distance? Thanks ahead of time! 回答1: App Engine doesn't treat GeoPt properties specially - it has no built in spatial indexing. There are a number of third-party libraries that add support for spatial indexing, however. The best one (in my opinion) being geomodel.

How to query all entries from past 6 hours ( datetime) in GQL?

余生长醉 提交于 2019-11-28 08:26:57
I have a simple table in Google App Engine with a date field. I want to query all the rows with the date field valued between now and 6 hours ago. How do I form this query? SELECT * FROM simpletable WHERE datefield < DATETIME(year, month, day, hour, minute, second) computing those year, month, &c, in your application code. I know you say GQL, but here's a python helper function I use: import datetime def seconds_ago(time_s): return datetime.datetime.now() - datetime.timedelta(seconds=time_s) There may well be a more concise way to write it: I'm not a python expert and went with the first thing

What's the best way to count results in GQL?

混江龙づ霸主 提交于 2019-11-27 11:35:02
I figure one way to do a count is like this: foo = db.GqlQuery("SELECT * FROM bar WHERE baz = 'baz') my_count = foo.count() What I don't like is my count will be limited to 1000 max and my query will probably be slow. Anyone out there with a workaround? I have one in mind, but it doesn't feel clean. If only GQL had a real COUNT Function... +1 to Jehiah's response. Official and blessed method on getting object counters on GAE is to build sharded counter . Despite heavily sounding name, this is pretty straightforward. You have to flip your thinking when working with a scalable datastore like GAE

Python: DISTINCT on GQuery result set (GQL, GAE)

可紊 提交于 2019-11-27 06:09:38
问题 Imagine you got an entity in the Google App Engine datastore, storing links for anonymous users. You would like to perform the following SQL query, which is not supported: SELECT DISTINCT user_hash FROM links Instead you could use: user = db.GqlQuery("SELECT user_hash FROM links") How to use Python most efficiently to filter the result, so it returns a DISTINCT result set? How to count the DISTINCT result set? 回答1: A set is good way to deal with that: >>> a = ['google.com', 'livejournal.com',

How to query all entries from past 6 hours ( datetime) in GQL?

此生再无相见时 提交于 2019-11-27 02:12:51
问题 I have a simple table in Google App Engine with a date field. I want to query all the rows with the date field valued between now and 6 hours ago. How do I form this query? 回答1: SELECT * FROM simpletable WHERE datefield < DATETIME(year, month, day, hour, minute, second) computing those year, month, &c, in your application code. 回答2: I know you say GQL, but here's a python helper function I use: import datetime def seconds_ago(time_s): return datetime.datetime.now() - datetime.timedelta

What&#39;s the best way to count results in GQL?

对着背影说爱祢 提交于 2019-11-26 15:37:54
问题 I figure one way to do a count is like this: foo = db.GqlQuery("SELECT * FROM bar WHERE baz = 'baz') my_count = foo.count() What I don't like is my count will be limited to 1000 max and my query will probably be slow. Anyone out there with a workaround? I have one in mind, but it doesn't feel clean. If only GQL had a real COUNT Function... 回答1: +1 to Jehiah's response. Official and blessed method on getting object counters on GAE is to build sharded counter. Despite heavily sounding name,

Google App Engine: Is it possible to do a Gql LIKE query?

筅森魡賤 提交于 2019-11-26 11:05:36
Simple one really. In SQL, if I want to search a text field for a couple of characters, I can do: SELECT blah FROM blah WHERE blah LIKE '%text%' The documentation for App Engine makes no mention of how to achieve this, but surely it's a common enough problem? Dave Webb BigTable, which is the database back end for App Engine, will scale to millions of records. Due to this, App Engine will not allow you to do any query that will result in a table scan, as performance would be dreadful for a well populated table. In other words, every query must use an index. This is why you can only do = , > and

Google App Engine: Is it possible to do a Gql LIKE query?

亡梦爱人 提交于 2019-11-26 03:29:29
问题 Simple one really. In SQL, if I want to search a text field for a couple of characters, I can do: SELECT blah FROM blah WHERE blah LIKE \'%text%\' The documentation for App Engine makes no mention of how to achieve this, but surely it\'s a common enough problem? 回答1: BigTable, which is the database back end for App Engine, will scale to millions of records. Due to this, App Engine will not allow you to do any query that will result in a table scan, as performance would be dreadful for a well