Reputation: 6515
I'm just staring off with GAE. So like many I'm used to standard SQL.
Typically when you want to select data that has a certain field value you use:
SELECT <columns> FROM <table> WHERE <column> = <wanted value>
Is the correct way to do this in GAE
<Model Class>.all().filter('<column> =', <wanted value>)
Or is there a more efficient way?
EDIT: Also I should note in this particular case I only want one result returned. So is there another command so that it doesn't keep looking after if finds a result?
Upvotes: 4
Views: 592
Reputation: 16233
Your code is pretty close to what you're looking for - it constructs a Query object which can be used to query the datastore. To actually get a result, you'll need to execute the query. To get a single result, you'll want to use the get()
method:
result = <Model Class>.all().filter('<column> =', <wanted value>).get()
Upvotes: 6
Reputation: 43487
You probably want Model.gql('where column = :value', value=something) which returns a GqlQuery
upon which a GqlQuery.get() returns a single item.
Upvotes: 1