JK140
JK140

Reputation: 785

Google App Engine - query vs. filter clarification

My model:

 class User(ndb.Model):
    name = ndb.StringProperty()

Is there any difference in terms of efficiency/cost/speed between the following two queries?

 u = User.query(User.name==name).get()

 u = User.query().filter(User.name==name).get()

Should I use one of them over the other? I assume the 2nd one is worse because it firsts get the entire User class queryset and then applies the filter?

Upvotes: 0

Views: 83

Answers (1)

minou
minou

Reputation: 16563

There is no difference in functionality between the two so you can choose whatever you like best. On the google documentation, they show these two examples:

query = Account.query(Account.userid >= 40, Account.userid < 50)

and

query1 = 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

and state:

query3 is equivalent to the query variable from the previous example.

Upvotes: 2

Related Questions