def Put( entities, **kwargs ):
"""
Store one or more entities in the data store.
The entities may be new or previously existing. For new entities,
``Put()`` will fill in the app id and key assigned by the data store.
:param entities: Entity or list of entities to be stored.
:type entities: :class:`server.db.Entity` | list of :class:`server.db.Entity`
:param config: Optional configuration to use for this request. This must be specified\
as a keyword argument.
:type config: dict
:returns: If the argument ``entities`` is a single :class:`server.db.Entity`, \
a single Key is returned. If the argument is a list of :class:`server.db.Entity`, \
a list of Keys will be returned.
:rtype: Key | list of keys
:raises: :exc:`TransactionFailedError`, if the action could not be committed.
"""
if isinstance( entities, Entity ):
entities._fixUnindexedProperties()
elif isinstance( entities, list ):
for entity in entities:
assert isinstance( entity, Entity )
entity._fixUnindexedProperties()
if conf["viur.db.caching" ]>0:
if isinstance( entities, Entity ): #Just one:
if entities.is_saved(): #Its an update
memcache.delete( str( entities.key() ), namespace=__CacheKeyPrefix__, seconds=__cacheLockTime__ )
elif isinstance( entities, list ):
for entity in entities:
assert isinstance( entity, Entity )
if entity.is_saved(): #Its an update
memcache.delete( str( entity.key() ), namespace=__CacheKeyPrefix__, seconds=__cacheLockTime__ )
return( datastore.Put( entities, **kwargs ) )
评论列表
文章目录