简体   繁体   中英

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 ?

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.

You may use gql also.

channelToken = User.gql("WHERE userId = :1", "1").get().channelToken

To delete all the records which has userId = 1

users = User.gql("WHERE userId = :1", "1").fetch()
for user in users:
    user.key.delete()

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