Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple filters vs OR , ndb query

What is the difference between these queries:

  1. With consequent filters:

    qry1 = Account.query() # Retrieve all Account entitites
    qry2 = qry1.filter(Account.userid >= 40) # Filter on userid >= 40
    qry3 = qry2.filter(Account.userid < 50) # Filter on userid < 50 as well
    
  2. Using ndb.OR:

    qry = Article.query(ndb.OR(Account.userid >= 40,
                           Account.userid < 50))
    
  3. Using ndb.AND:

    qry = Article.query(ndb.AND(Account.userid >= 40,
                            Account.userid < 50))
    
like image 792
david Avatar asked Oct 18 '14 09:10

david


1 Answers

The first query does an AND. Thus, only the entities that match both inequalities will be returned by the query. The second query does an OR. Thus, entities that match either of the filters will be returned. For more information about ndb queries, take a look at NDB Queries.

like image 117
Thanos Makris Avatar answered Sep 29 '22 08:09

Thanos Makris