'''
Aiming for the following:
query = Account.query() # Retrieve all Account entitites
query2 = query1.filter(Account.userid >= 40) # Filter on userid >= 40
query3 = query2.filter(Account.userid < 50) # Filter on userid < 50 too
'''
from google.appengine.ext import ndb
import models
modelmap = {
'Account' : models.account
# etc
}
# this would come from the GET request, just mocked up here as an example
restquery = {
'entity' : 'Account'
'filters' = [
{'field' : 'userid',
'operator' : '>=',
'value' : 40},
{'field' : 'userid',
'operator' : '<',
'value' : 50},
]
}
model = models[restquery['entity']]
query = model.query()
for filter in filters:
if filter['operator'] == '==':
query.filter(model._properties[filter['field']] == filter['value'])
elif filter['operator'] == '<':
query.filter(model._properties[filter['field']] < filter['value'])
elif filter['operator'] == '<=':
query.filter(model._properties[filter['field']] <= filter['value'])
elif filter['operator'] == '>':
query.filter(model._properties[filter['field']] > filter['value'])
elif filter['operator'] == '>=':
query.filter(model._properties[filter['field']] >= filter['value'])
elif filter['operator'] == '!=':
query.filter(model._properties[filter['field']] != filter['value'])
elif filter['operator'] == '<':
query.filter(model._properties[filter['field']].IN(filter['value']))
Hi Simon,
Cloud Datastore client libraries supported by App Engine standard can be seen by visiting the link here. To get an overview of the Python NDB client library along with sample code please visit the link here.
Since your question is technical in nature I would suggest that you post your question on StackOverflow as Google Groups are reserved for general product discussion, StackOverflow for technical questions whereas Issue Tracker for product bugs and feature requests. To get a better support you should post to the relevant forum. Please read the Community Support article for better understanding.
Hope this helps.
Hello Simon,
Please look at this document "The Python NDB Client Library Overview" which was provided earlier that describes Python NDB Client Library which allows App Engine Python apps to connect to Cloud Datastore. The document also provides sample codes.