Uncategorized

Simple GQL Query Syntax

April 26, 2008

author:

Simple GQL Query Syntax

As I go through the process of getting familiar with Google AppEngine, I’ll post interesting things I learn (mostly so I can find them later). Here’s a quick note on GQL query syntax:

Assuming a model called Customer, you can use:

1) customers = db.GqlQuery(“SELECT * FROM Customer ORDER BY name LIMIT 10”)

2) And since GQL queries always return data objects, you can skip the SELECT * and abbreviate to:

customers = Customer.gql(“ORDER BY name LIMIT 10”)

3) You can also use parameters like this:

customers = Customer.gql(“WHERE name = :1 ORDER BY name LIMIT 10”, “Smith”)

4) And finally, #3 with named parameters like this:

customers = Customer.gql(“WHERE name= :person ORDER BY name LIMIT 10″, person=”Smith”)

Founder NftyDreams; founder Decentology; co-founder DNN Software; educator; Open Source proponent; Microsoft MVP; tech geek; creative thinker; husband; dad. Personal blog: http://www.kalyani.com. Twitter: @techbubble
Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.