简体   繁体   中英

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?

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

您可能需要Model.gql (“ where column =:value”,value = something),该模型返回一个GqlQueryGqlQuery.get()在该GqlQuery返回单个项目。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM