1
假設我有創建一個新的實體如下:如果我將實體放入Google App Engine數據存儲區兩次,會發生什麼情況?
item = Item()
item.property = property_value
item_key1 = item.put()
問題1:在同一個文件中這一行後,如果我做了以下的結果:
item_key2 = item.put()
現在,數據存儲是否有一個實體 - 項目,還是數據存儲有兩個分別由item_key1和item_key2標識的實體?
問題2:在同一個文件後立即這一行(不包括在問題1中添加的代碼),如果我做了以下的結果:
item.property = new_property_value
item.put()
是否在數據存儲中的同一實體得到更新,或者數據存儲是否創建了一個新的實體,其屬性等於new_property_value?
對問題2的後續問題:如果數據存儲在這種情況下創建了兩個實體,是否意味着我必須執行以下操作來更新實體,即使該實體剛創建在同一個函數中?
item = Item()
item.property = property_value
# entity written to datastore
item_key = item.put()
# get the entity from the datastore to make sure it is the entity to update
item = item_key.get()
# update the value
item.property = new_property_value
# put it back to datastore
item.put()
這看起來非常愚蠢,並且在數據存儲寫入中花費兩倍多。
謝謝。
有意義。謝謝。 – BlackJerry 2014-09-22 01:16:56