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.

Please kindly note that Google Groups hosts discussion forums where users 
are likely to find information like service status updates and release 
notes, and ranging from book recommendations to creative shortcuts. If you 
believe that what you've encountered is platform specific issue you can 
report this by creating an issue in the Issue Tracker 
<https://cloud.google.com/support/docs/issue-trackers> and Google Cloud 
Support team member will assist you to resolve your issue.  If your issue 
is not a platform issue but rather a problem with how you've configured 
your code, although you're not sure what it may be specifically, you should 
post to StackOverflow <http://www.stackoverflow.com/> as it was suggested 
at the previous message and community of developers will assist you. 


On Monday, December 10, 2018 at 11:01:50 PM UTC-5, Simon Cox wrote:
>
> 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/237c718a-85c4-49b6-8bb8-ee8cf37d2f0f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to