python - What happens if I put an entity to Google App Engine Datastore twice? -
suppose have create new entity follows:
item = item() item.property = property_value item_key1 = item.put()
question 1: in same file after line, happens if following:
item_key2 = item.put()
now, datastore have 1 entity - item, or datastore have 2 entities identified item_key1 , item_key2, respectively?
question 2: in same file after line (without code added in question 1), happens if following:
item.property = new_property_value item.put()
does same entity in datastore updated, or datastore create new entity property equals new_property_value?
a follow question question 2: if datastore creates 2 entities in case, mean have following update entity, if entity created in same function?
item = item() item.property = property_value # entity written datastore item_key = item.put() # entity datastore make sure entity update item = item_key.get() # update value item.property = new_property_value # put datastore item.put()
this looks silly, , cost twice in datastore write.
thanks.
the answer both of questions have 1 entity.
when put entity datastore, overwrites existing entity same key. once call put()
, item has unique key. every subsequent put()
on same item overwrite existing entity in datastore.
you have 2 entities in following case:
item = item() item_key1 = item.put() item = item() item_key2 = item.put()
Comments
Post a Comment