Store
elva.store
Module holding store components.
Classes:
-
SQLiteStore
–Store component saving Y updates in an ELVA SQLite database.
Functions:
-
get_metadata
–Retrieve metadata from a given ELVA SQLite database.
-
set_metadata
–Set
metadata
in an ELVA SQLite database atpath
.
Attributes:
-
SQLiteStoreState
–The states of the
SQLiteStore
component.
SQLiteStoreState = create_component_state('SQLiteStoreState')
module-attribute
The states of the SQLiteStore
component.
SQLiteStore(ydoc, identifier, path)
Bases: Component
Store component saving Y updates in an ELVA SQLite database.
Parameters:
-
ydoc
(Doc
) –instance of the synchronized Y Document.
-
identifier
(str | None
) –identifier of the synchronized Y Document. If
None
, it is tried to be retrieved from themetadata
table in the SQLite database. -
path
(str
) –path where to store the SQLite database.
Methods:
-
get_metadata
–Retrieve metadata from a given ELVA SQLite database.
-
set_metadata
–Set given metadata in a given ELVA SQLite database.
-
get_updates
–Read out the updates saved in the file.
-
before
–Hook executed before the component sets its
RUNNING
state. -
run
–Hook writing updates from the internal buffer to file.
-
cleanup
–Hook cancelling subscription to changes and closing the database.
Attributes:
-
ydoc
(Doc
) –Instance of the synchronized Y Document.
-
identifier
(str
) –Identifier of the synchronized Y Document.
-
path
(Path
) –Path where to store the SQLite database.
-
states
(SQLiteStoreState
) –The states this component can have.
Source code in src/elva/store.py
_subscription
instance-attribute
(while running) Object holding subscription information to changes in ydoc
.
_stream_send
instance-attribute
(while running) Stream to send Y Document updates or flow control objects to.
_stream_recv
instance-attribute
(while running) Stream to receive Y Document updates or flow control objects from.
_db
instance-attribute
(while running) SQLite connection to the database file at path
.
_cursor
instance-attribute
(while running) SQLite cursor operating on the _db
connection.
ydoc = ydoc
instance-attribute
Instance of the synchronized Y Document.
identifier = identifier
instance-attribute
Identifier of the synchronized Y Document.
path = Path(path)
instance-attribute
Path where to store the SQLite database.
_lock = Lock()
instance-attribute
Object for restricted resource management.
states
property
The states this component can have.
get_metadata()
async
Retrieve metadata from a given ELVA SQLite database.
Returns:
-
dict
–mapping of metadata keys to values.
Source code in src/elva/store.py
set_metadata(metadata, replace=False)
async
Set given metadata in a given ELVA SQLite database.
Parameters:
-
metadata
(dict
) –mapping of metadata keys to values.
-
replace
(bool
, default:False
) –flag whether to just insert or update keys (
False
) or to delete absent keys as well (True
).
Source code in src/elva/store.py
get_updates()
async
Read out the updates saved in the file.
Returns:
-
list
–a list of updates in the order they were applied to the YDoc.
Source code in src/elva/store.py
_on_transaction_event(event)
Hook called on changes in ydoc
.
When called, the event
data are written to the ELVA SQLite database.
Parameters:
-
event
(TransactionEvent
) –object holding event information of changes in
ydoc
.
Source code in src/elva/store.py
_ensure_metadata_table()
async
Hook called before the store sets its RUNNING
state to ensure a table metadata
exists.
Source code in src/elva/store.py
_ensure_identifier()
async
Hook called before the store sets its started
signal to ensure the UUID of the YDoc contents is saved.
Source code in src/elva/store.py
_ensure_update_table()
async
Hook called before the store sets its started
signal to ensure a table yupdates
exists.
Source code in src/elva/store.py
_merge()
async
Hook to read in and apply updates from the ELVA SQLite database and write divergent history updates to file.
Source code in src/elva/store.py
_initialize()
async
Hook initializing the database, i.e. ensuring the presence of connection and the ELVA SQL database scheme.
Source code in src/elva/store.py
_connect_database()
async
Hook connecting to the data base path.
_disconnect_database()
async
Hook closing the database connection if initialized.
Source code in src/elva/store.py
_write(update)
async
Hook writing update
to the yupdates
ELVA SQLite database table.
Parameters:
-
update
(bytes
) –the update to write to the ELVA SQLite database file.
Source code in src/elva/store.py
before()
async
Hook executed before the component sets its RUNNING
state.
The ELVA SQLite database is being initialized and read.
Also, the component subscribes to changes in ydoc
.
Source code in src/elva/store.py
run()
async
Hook writing updates from the internal buffer to file.
Source code in src/elva/store.py
cleanup()
async
Hook cancelling subscription to changes and closing the database.
Source code in src/elva/store.py
get_metadata(path)
Retrieve metadata from a given ELVA SQLite database.
Parameters:
Raises:
-
FileNotFoundError
–if there is no file present.
-
OperationalError
–if there is no
metadata
table in the database.
Returns:
-
dict
–mapping of metadata keys to values.
Source code in src/elva/store.py
set_metadata(path, metadata, replace=False)
Set metadata
in an ELVA SQLite database at path
.
Parameters:
-
path
(str | Path
) –path to the ELVA SQLite database.
-
metadata
(dict[str, str]
) –mapping of metadata keys to values.
-
replace
(bool
, default:False
) –flag whether to just insert or update keys (
False
) or to delete absent keys as well (True
).