aiida.storage.sqlite_temp package#

A temporary backend, using an in-memory sqlite database.

This backend is intended for testing and demonstration purposes. Whenever it is instantiated, it creates a fresh storage backend, and destroys it when it is garbage collected.

Submodules#

Definition of the SqliteTempBackend backend.

class aiida.storage.sqlite_temp.backend.SqliteTempBackend(profile: aiida.manage.configuration.profile.Profile)[source]#

Bases: aiida.orm.implementation.storage_backend.StorageBackend

A temporary backend, using an in-memory sqlite database.

This backend is intended for testing and demonstration purposes. Whenever it is instantiated, it creates a fresh storage backend, and destroys it when it is garbage collected.

__abstractmethods__ = frozenset({})#
__init__(profile: aiida.manage.configuration.profile.Profile)[source]#

Initialize the backend, for this profile.

Raises

~aiida.common.exceptions.UnreachableStorage if the storage cannot be accessed

Raises

~aiida.common.exceptions.IncompatibleStorageSchema if the profile’s storage schema is not at the latest version (and thus should be migrated)

Raises
raises

aiida.common.exceptions.CorruptStorage if the storage is internally inconsistent

__module__ = 'aiida.storage.sqlite_temp.backend'#
__str__() str[source]#

Return a string showing connection details for this instance.

_abc_impl = <_abc_data object>#
_clear(recreate_user: bool = True) None[source]#

Clear the storage, removing all data.

Warning

This is a destructive operation, and should only be used for testing purposes.

Parameters

recreate_user – Re-create the default User for the profile, after clearing the storage.

_default_user: Optional['User']#
_read_only = False#
property authinfos#

Return the collection of authorisation information objects

bulk_insert(entity_type: EntityTypes, rows: list[dict], allow_defaults: bool = False) list[int][source]#

Insert a list of entities into the database, directly into a backend transaction.

Parameters
  • entity_type – The type of the entity

  • data – A list of dictionaries, containing all fields of the backend model, except the id field (a.k.a primary key), which will be generated dynamically

  • allow_defaults – If False, assert that each row contains all fields (except primary key(s)), otherwise, allow default values for missing fields.

Raises

IntegrityError if the keys in a row are not a subset of the columns in the table

Returns

The list of generated primary keys for the entities

bulk_update(entity_type: EntityTypes, rows: list[dict]) None[source]#

Update a list of entities in the database, directly with a backend transaction.

Parameters
  • entity_type – The type of the entity

  • data – A list of dictionaries, containing fields of the backend model to update, and the id field (a.k.a primary key)

Raises

IntegrityError if the keys in a row are not a subset of the columns in the table

close()[source]#

Close the storage access.

property comments#

Return the collection of comments

property computers#

Return the collection of computers

static create_profile(name: str = 'temp', default_user_email='user@email.com', sandbox_path: str | Path | None = None, options: dict | None = None, debug: bool = False) Profile[source]#

Create a new profile instance for this backend, from the path to the zip file.

delete_nodes_and_connections(pks_to_delete: Sequence[int])[source]#

Delete all nodes corresponding to pks in the input and any links to/from them.

This method is intended to be used within a transaction context.

Parameters

pks_to_delete – a sequence of node pks to delete

Raises

AssertionError if a transaction is not active

get_backend_entity(model) aiida.orm.implementation.entities.BackendEntity[source]#

Return the backend entity that corresponds to the given Model instance.

get_global_variable(key: str)[source]#

Return a global variable from the storage.

Parameters

key – the key of the setting

Raises

KeyError if the setting does not exist

get_info(detailed: bool = False) dict[source]#

Return general information on the storage.

Parameters

detailed – flag to request more detailed information about the content of the storage.

Returns

a nested dict with the relevant information.

get_repository() aiida.repository.backend.sandbox.SandboxRepositoryBackend[source]#

Return the object repository configured for this backend.

get_session() sqlalchemy.orm.session.Session[source]#

Return an SQLAlchemy session.

property groups#

Return the collection of groups

property in_transaction: bool#

Return whether a transaction is currently active.

property is_closed: bool#

Return whether the storage is closed.

property logs#

Return the collection of logs

maintain(dry_run: bool = False, live: bool = True, **kwargs) None[source]#

Perform maintenance tasks on the storage.

If full == True, then this method may attempt to block the profile associated with the storage to guarantee the safety of its procedures. This will not only prevent any other subsequent process from accessing that profile, but will also first check if there is already any process using it and raise if that is the case. The user will have to manually stop any processes that is currently accessing the profile themselves or wait for it to finish on its own.

Parameters
  • full – flag to perform operations that require to stop using the profile to be maintained.

  • dry_run – flag to only print the actions that would be taken without actually executing them.

classmethod migrate(profile: aiida.manage.configuration.profile.Profile)[source]#

Migrate the storage of a profile to the latest schema version.

If the schema version is already the latest version, this method does nothing. If the storage is empty/uninitialised, then it will be initialised at head.

Raises

~aiida.common.exceptions.UnreachableStorage if the storage cannot be accessed

property nodes#

Return the collection of nodes

query() aiida.storage.sqlite_zip.orm.SqliteQueryBuilder[source]#

Return an instance of a query builder implementation for this backend

set_global_variable(key: str, value, description: str | None = None, overwrite=True) None[source]#

Set a global variable in the storage.

Parameters
  • key – the key of the setting

  • value – the value of the setting

  • description – the description of the setting (optional)

  • overwrite – if True, overwrite the setting if it already exists

Raises

ValueError if the key already exists and overwrite is False

transaction() Iterator[sqlalchemy.orm.session.Session][source]#

Open a transaction to be used as a context manager.

If there is an exception within the context then the changes will be rolled back and the state will be as before entering. Transactions can be nested.

property users#

Return the collection of users

classmethod version_head() str[source]#

Return the head schema version of this storage backend type.

classmethod version_profile(profile: Profile) str | None[source]#

Return the schema version of the given profile’s storage, or None for empty/uninitialised storage.

Raises

~aiida.common.exceptions.UnreachableStorage if the storage cannot be accessed