Selecting data from Google App Engine datastore by field value

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?

Answers


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()

You probably want Model.gql('where column = :value', value=something) which returns a GqlQuery upon which a GqlQuery.get() returns a single item.


Need Your Help

How do I set up a build server on the cheap/free?

automation build-automation build-server

Currently I'm tasked with doing the daily build. We have an ASP.NET 2005 website with a SQL Server 2005 backend. Our current source control is Visual Source Safe 2005.

How populate database records into my table ajax

javascript c# jquery ajax

So i go this information and have a empty table name categorytable so i have to have records stored in categoryList for the below code to work. so what do i write in categoryList which is to fetch ...