Sunil Garg Sunil Garg - 2 months ago 10
Python Question

not able to retrieve data from datastore GAE

I have a Class User

class User(db.Model):
userId = db.StringProperty()
email = db.StringProperty()
channelToken = db.StringProperty()


I inserted a record with

user = User(key_name='1',userId='1',email='abc@gmail.com',channelToken='123')
user.put()


It is perfectly inserted. But now when I am trying to retrieve it, it is showing an error

channelToken= db.GqlQuery("SELECT channelToken FROM User WHERE userId=1")
logging.info("Found Channel : " + str(channelToken))


it is showing

<google.appengine.ext.db.GqlQuery object at 0xfe112370>" is not a string.


Am I doing something wrong ?

Answer

Referring https://cloud.google.com/appengine/docs/python/datastore/gqlqueryclass#GqlQuery

q = db.GqlQuery("SELECT channelToken FROM User WHERE userId=1") 
channelToken = q.get()

The logging was giving a memory location because GqlQuery returns an object.