python-2.7google-app-enginegoogle-cloud-datastoregqlgqlquery

GQL Queries - Retrieving specific data from query object


I'm building a database using Google Datastore. Here is my model...

class UserInfo(db.Model):

name = db.StringProperty(required = True)
password = db.StringProperty(required = True)
email = db.StringProperty(required = False)

...and below is my GQL Query. How would I go about retrieving the user's password and ID from the user_data object? I've gone through all the google documentation, find it hard to follow, and have spent ages trying various things I've read online but nothing has helped! I'm on Python 2.7.

user_data = db.GqlQuery('SELECT * FROM UserInfo WHERE name=:1', name_in)
user_info = user_data.get()

Solution

  • This is basic Python.

    From the query, you get a UserInfo instance, which you have stored in the user_info variable. You can access the data of an instance via dot notation: user_info.password and user_info.email.

    If this isn't clear, you really should do a basic Python tutorial before going any further.