簡體   English   中英

使用Python在Google AppEngine上的GQL中進行簡單的數據存儲/檢索

[英]Simple data storing / retrieving in GQL on Google AppEngine in Python

我有一個問題,可能是由於我不了解GQL的工作原理(這是我的第一天)。 我正在使用google.appengine.ext.db數據存儲來開發Google AppEngine(現在在本地)。

我只是創建一個具有特定ID的用戶,然后嘗試通過過濾以僅包含具有該ID的記錄來檢索它。 當我嘗試此操作時,它什么都不返回,但是當我獲得全部信息時,一次又一次地迭代並比較ID,它會找到記錄。 我確實沒有看到一些愚蠢的錯誤。 這是代碼:

def datastore_key():
    return db.Key.from_path('MyUsers', 'all')

class MyUser(db.Model):
    my_id = db.TextProperty()


[...]

 user = MyUser(parent=datastore_key())
 user.my_id = "7wjew1"
 user.put()

 users = MyUser.all()
 users.ancestor(datastore_key())
 users.filter("my_id = ", "7wjew1") # WTF - why isn't this working???
 print users[0] # is None, users list is empty

 # now, let's get all users
 users = MyUser.all()
 users.ancestor(datastore_key())
 # and iterate through the list to check for ids
 for user in users:
     if user.linkedin_id == user_id:
         print "ids are the same"
         # surprise, it prints the "ids are the same" - wtf?

好的,我想有時候寫一個問題是件好事,這樣您就可以自己想出一個答案。 我將TextProperty更改為StringProperty並且它起作用了:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM