Session: Storing entities in session
To store entities inside session object use the store
method.
def store(self, entity, key=None, change_vector=None):
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,
forces concurrency check with given change_vector.
session.store(entity, change_vector=change_vector)
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 change_vector
session.store(entity, key="doc/1", change_vector=change_vector)
Parameters | ||
---|---|---|
entity | object | Entity that will be stored |
key | str | Entity will be stored under this key, (None to generate automatically) |
change_vector | str | Current entity change_vectore, used for concurrency checks (None to skip check) |
Example
# generate Id automatically
# when we have a new and empty database and conventions are not changed: 'employees/1-A'
employee = Employee("John", "Doe")
session.store(employee)
session.save_changes()