Thanks Omair.

I strongly suspect that this question will be moderated on StackOverflow as 
it is opinion / best-practice based.

On Friday, December 7, 2018 at 3:17:08 PM UTC, Omair (Cloud Platform 
Support) wrote:
>
> Hi Simon,
>
> Cloud Datastore client libraries supported by App Engine standard can be 
> seen by visiting the link here 
> <https://cloud.google.com/datastore/docs/reference/libraries#google_app_engine_standard_environment_client_libraries>.
>  
> To get an overview of the Python NDB client library along with sample code 
> please visit the link here 
> <https://cloud.google.com/appengine/docs/standard/python/ndb/>.
>
> 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 
> <https://cloud.google.com/support/docs/community>article for better 
> understanding. 
>
> Hope this helps. 
>
>
> On Thursday, December 6, 2018 at 2:13:01 PM UTC-5, Simon Cox wrote:
>>
>> I would like to allow the client side to arbitrarily query NDB, using the 
>> full query syntax available for NDB (which can filter on unlimited fields 
>> with ==, <, <=, >, >=, !=, IN, and can use OR and AND).
>>
>> How do I encode the query in a GET request? And how do I take the encoded 
>> query and convert to an NDB query server-side?
>>
>> Are there any libraries that already solve the problem? I'm using Python 
>> 2.7.
>>
>> Here is an (untested) attempt at what I'm trying to do, but which doesn't 
>> do any boolean operations:
>>
>> '''
>>
>>     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'
>> ]))  
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-appengine+unsubscr...@googlegroups.com.
To post to this group, send email to google-appengine@googlegroups.com.
Visit this group at https://groups.google.com/group/google-appengine.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-appengine/2ea06f9a-4b13-45ec-a9d7-194bdb89d618%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
  • [google-appeng... Simon Cox
    • [google-a... 'Omair (Cloud Platform Support)' via Google App Engine
      • [goog... Simon Cox
        • [... 'Mohammad I (Cloud Platform Support)' via Google App Engine

Reply via email to