Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing "Starts with" and "Ends with" queries with Google App Engine

Am wondering if anyone can provide some guidance on how I might implement a starts with or ends with query against a Datastore model using Python?

In pseudo code, it would work something like...

Query for all entities A where property P starts with X

or

Query for all entities B where property P ends with X

Thanks, Matt

like image 675
Matty Avatar asked Oct 12 '09 13:10

Matty


1 Answers

You can do a 'starts with' query by using inequality filters:

MyModel.all().filter('prop >=', prefix).filter('prop <', prefix + u'\ufffd')

Doing an 'ends with' query would require storing the reverse of the string, then applying the same tactic as above.

like image 95
Nick Johnson Avatar answered Nov 05 '22 10:11

Nick Johnson