gql

What is a good pattern for inexact queries in the Google App Engine Datastore?

北慕城南 提交于 2019-12-03 20:19:56
The Google App Engine Datastore querying language (gql) does not offer inexact operators like "LIKE" or even case insensitivity. One can get around the case sensitive issue by storing a lower-case version of a field. But what if I want to search for a person but I'm not sure of the spelling of the name? Is there an accepted pattern for dealing with this scenario? Quoting from the documentation: Tip: Query filters do not have an explicit way to match just part of a string value, but you can fake a prefix match using inequality filters: db.GqlQuery("SELECT * FROM MyModel WHERE prop >= :1 AND

Build a GQL query (for Google App Engine) that has a condition on ReferenceProperty

允我心安 提交于 2019-12-03 15:42:20
Say I have the following model: class Schedule(db.Model): tripCode = db.StringProperty(required=True) station = db.ReferenceProperty(Station, required=True) arrivalTime = db.TimeProperty(required=True) departureTime = db.TimeProperty(required=True) And let's say I have a Station object stored in the var foo . How do I assemble a GQL query that returns all Schedule objects with a reference to the Station object referenced by foo ? This is my best (albeit incorrect ) attempt to form such a query: myQuery = "SELECT * FROM Schedule where station = " + str(foo.key()) Once again foo is a Station

Querying for N random records on Appengine datastore

喜夏-厌秋 提交于 2019-12-03 12:37:02
问题 I'm trying to write a GQL query that returns N random records of a specific kind. My current implementation works but requires N calls to the datastore. I'd like to make it 1 call to the datastore if possible. I currently assign a random number to every kind that I put into the datastore. When I query for a random record I generate another random number and query for records > rand ORDER BY asc LIMIT 1. This works, however, it only returns 1 record so I need to do N queries. Any ideas on how

Google App Engine Query (not filter) for children of an entity

眉间皱痕 提交于 2019-12-03 03:30:39
Are the children of an entity available in a Query? Given: class Factory(db.Model): """ Parent-kind """ name = db.StringProperty() class Product(db.Model): """ Child kind, use Product(parent=factory) to make """ @property def factory(self): return self.parent() serial = db.IntegerProperty() Assume 500 factories have made 500 products for a total of 250,000 products. Is there a way to form a resource-efficient query that will return just the 500 products made by one particular factory? The ancestor method is a filter, so using e.g. Product.all().ancestor(factory_1) would require repeated calls

How do I query in GQL using the entity key

倖福魔咒の 提交于 2019-12-03 01:50:37
问题 How do I write a query against the entity key using GQL in the Google App Engine Data Viewer ? In the viewer, the first column (Id/Name) displays as name=_1 , in the detail view it shows the key as Decoded entity key: Programme: name=_1 Entity key: agtzcG9................... This query does not work: SELECT * FROM Programme where name = '_1' 回答1: You can use the entity's key to retrieve it: SELECT * FROM Programme where __key__ = KEY('agtzcG9...................') And, you should be able to

GQL query with numeric id in datastore viewer

岁酱吖の 提交于 2019-12-03 01:04:37
问题 I want to build GQL query to get an object using its numeric id. I'm doing this in Datastore viewer in App management console, so I can't use Model.get_by_id(numeric_id). Something like SELECT * FROM Model WHERE id = <numeric_id> also doesn't work. 回答1: Try this: SELECT * FROM Model where __key__ = KEY('Model', <numeric_id>) 回答2: Unfortunately, there does not appear to be a way to write a query equivalent to SELECT * FROM Model WHERE id = <numeric_id> which would select all Model entities

In Google DataStore GQL, how can I group the WHERE terms?

荒凉一梦 提交于 2019-12-02 19:09:44
问题 I need to group terms in the WHERE clause. For example, WHERE (param1='foo1' OR param1='foo2') AND (param2='bar1' OR param2='bar2') But it's giving me a syntax error saying that the parentheses are "unexpected". The actual error is: GQL query error: Encountered "(" at line 1, column 29. Was expecting one of: "false", "null", "true", <INTEGER>, <DOUBLE>, <SINGLE_QUOTE_STRING>, <DOUBLE_QUOTE_STRING>, <UNQUOTED_NAME>, <QUOTED_NAME>, <NAME_BINDING_SITE>, <POSITION_BINDING_SITE> So, is there any

How do I query in GQL using the entity key

大兔子大兔子 提交于 2019-12-02 14:02:46
How do I write a query against the entity key using GQL in the Google App Engine Data Viewer ? In the viewer, the first column (Id/Name) displays as name=_1 , in the detail view it shows the key as Decoded entity key: Programme: name=_1 Entity key: agtzcG9................... This query does not work: SELECT * FROM Programme where name = '_1' Adam Crossland You can use the entity's key to retrieve it: SELECT * FROM Programme where __key__ = KEY('agtzcG9...................') And, you should be able to query using the name similarly: SELECT * FROM Programme where __key__ = KEY(Programme, '_1')

Parse Error: Invalid WHERE Identifier at symbol (

我与影子孤独终老i 提交于 2019-12-02 13:40:31
I am trying to get a result using an optional parameters. result = Tester.gql("WHERE (first_name IS NULL OR first_name = :first_name)" "AND (last_name IS NULL OR last_name = :last_name)" "AND (birth_date IS NULL OR birth_date = :birth_date)" "AND (test_voucher IS NULL OR test_voucher = :test_voucher)", first_name=first_name, last_name=last_name, birth_date=birth_date, test_voucher=test_voucher) However, I am getting an error about parsing when I use this GQL script. { "error": { "message": "Parse Error: Invalid WHERE Identifier at symbol (" } } I am trying to figure out what is wrong in my GQL

In Google DataStore GQL, how can I group the WHERE terms?

情到浓时终转凉″ 提交于 2019-12-02 08:38:36
I need to group terms in the WHERE clause. For example, WHERE (param1='foo1' OR param1='foo2') AND (param2='bar1' OR param2='bar2') But it's giving me a syntax error saying that the parentheses are "unexpected". The actual error is: GQL query error: Encountered "(" at line 1, column 29. Was expecting one of: "false", "null", "true", <INTEGER>, <DOUBLE>, <SINGLE_QUOTE_STRING>, <DOUBLE_QUOTE_STRING>, <UNQUOTED_NAME>, <QUOTED_NAME>, <NAME_BINDING_SITE>, <POSITION_BINDING_SITE> So, is there any way for me to run that query? I believe the problem you're facing comes from the OR operator - GQL doesn