Session: Storing entities in session
To store entities inside session object use the store
method.
def store(self, entity, key=None, etag=None, force_concurrency_check=False):
Syntax
Extracts Id from entity using Conventions or generates new one if it is not available.
session.store(entity)
Extracts Id from entity using Conventions or generates new one if it is not available and forces concurrency check with given etag.
session.store(entity, etag=etag)
Stores entity in session with given id.
session.store(entity, key="doc/1")
Stores entity in session with given id and forces concurrency check with given etag
session.store(entity, key="doc/1", etag=etag)
Parameters | ||
---|---|---|
entity | object | Entity that will be stored |
key | str | Entity will be stored under this key, (None to generate automatically) |
etag | str | Current entity etag, used for concurrency checks (None to skip check) |
force_concurrency_check | bool | Force concurrency check (False as a default value) |
Example
# generate Id automatically
# # when we have a new and empty database and conventions are not changed: 'employees/1'
employee = Employee("John", "Doe")
session.store(employee)
session.save_changes()