aiida.storage.psql_dos.orm package#

Implementation of ORM backend entities.

Subpackages#

Submodules#

Module for the SqlAlchemy backend implementation of the AuthInfo ORM class.

class aiida.storage.psql_dos.orm.authinfos.SqlaAuthInfo(backend, computer, user)[source]#

Bases: SqlaModelEntity[DbAuthInfo], BackendAuthInfo

SqlAlchemy backend implementation for the AuthInfo ORM class.

COMPUTER_CLASS#

alias of SqlaComputer

MODEL_CLASS#

alias of DbAuthInfo

USER_CLASS#

alias of SqlaUser

__abstractmethods__ = frozenset({})#
__init__(backend, computer, user)[source]#

Construct a new instance.

Parameters:
Returns:

an aiida.orm.implementation.authinfos.BackendAuthInfo instance

__module__ = 'aiida.storage.psql_dos.orm.authinfos'#
__orig_bases__ = (aiida.storage.psql_dos.orm.entities.SqlaModelEntity[aiida.storage.psql_dos.models.authinfo.DbAuthInfo], <class 'aiida.orm.implementation.authinfos.BackendAuthInfo'>)#
__parameters__ = ()#
_abc_impl = <_abc._abc_data object>#
_model: ModelWrapper#
property computer#

Return the computer associated with this instance.

Returns:

aiida.orm.implementation.computers.BackendComputer

property enabled: bool#

Return whether this instance is enabled.

Returns:

boolean, True if enabled, False otherwise

get_auth_params()[source]#

Return the dictionary of authentication parameters

Returns:

a dictionary with authentication parameters

get_metadata()[source]#

Return the dictionary of metadata

Returns:

a dictionary with metadata

property id#

Get the id of this entity

Returns:

the entity id

property is_stored: bool#

Return whether the entity is stored.

Returns:

True if stored, False otherwise

set_auth_params(auth_params)[source]#

Set the dictionary of authentication parameters

Parameters:

auth_params – a dictionary with authentication parameters

set_metadata(metadata)[source]#

Set the dictionary of metadata

Parameters:

metadata – a dictionary with metadata

property user#

Return the user associated with this instance.

Returns:

aiida.orm.implementation.users.BackendUser

class aiida.storage.psql_dos.orm.authinfos.SqlaAuthInfoCollection(backend: StorageBackend)[source]#

Bases: BackendAuthInfoCollection

The collection of SqlAlchemy backend AuthInfo entries.

ENTITY_CLASS#

alias of SqlaAuthInfo

__annotations__ = {}#
__module__ = 'aiida.storage.psql_dos.orm.authinfos'#
__parameters__ = ()#
delete(pk)[source]#

Delete an entry from the collection.

Parameters:

pk – the pk of the entry to delete

SQLA implementations for the Comment entity and collection.

class aiida.storage.psql_dos.orm.comments.SqlaComment(backend, node, user, content=None, ctime=None, mtime=None)[source]#

Bases: SqlaModelEntity[DbComment], BackendComment

Comment implementation for Sqla.

MODEL_CLASS#

alias of DbComment

USER_CLASS#

alias of SqlaUser

__abstractmethods__ = frozenset({})#
__init__(backend, node, user, content=None, ctime=None, mtime=None)[source]#

Construct a SqlaComment.

Parameters:
  • node – a Node instance

  • user – a User instance

  • content – the comment content

  • ctime – The creation time as datetime object

  • mtime – The modification time as datetime object

__module__ = 'aiida.storage.psql_dos.orm.comments'#
__orig_bases__ = (aiida.storage.psql_dos.orm.entities.SqlaModelEntity[aiida.storage.psql_dos.models.comment.DbComment], <class 'aiida.orm.implementation.comments.BackendComment'>)#
__parameters__ = ()#
_abc_impl = <_abc._abc_data object>#
_model: ModelWrapper#
property content#

Return the comment content.

property ctime#

Return the creation time of the comment.

property mtime#

Return the modified time of the comment.

property node#

Return the comment’s node.

set_content(value)[source]#

Set the comment content.

set_mtime(value)[source]#

Set the modified time of the comment.

set_user(value)[source]#

Set the comment owner.

store()[source]#

Can only store if both the node and user are stored as well.

property user#

Return the comment owner.

property uuid: str#

Return the UUID of the comment.

class aiida.storage.psql_dos.orm.comments.SqlaCommentCollection(backend: StorageBackend)[source]#

Bases: BackendCommentCollection

SqlAlchemy implementation for the CommentCollection.

ENTITY_CLASS#

alias of SqlaComment

__annotations__ = {}#
__module__ = 'aiida.storage.psql_dos.orm.comments'#
__parameters__ = ()#
create(node, user, content=None, **kwargs)[source]#

Create a Comment for a given node and user

Parameters:
  • node – a Node instance

  • user – a User instance

  • content – the comment content

Returns:

a Comment object associated to the given node and user

delete(comment_id)[source]#

Remove a Comment from the collection with the given id

Parameters:

comment_id (int) – the id of the comment to delete

Raises:
  • TypeError – if comment_id is not an int

  • NotExistent – if Comment with ID comment_id is not found

delete_all()[source]#

Delete all Comment entries.

Raises:

IntegrityError – if all Comments could not be deleted

delete_many(filters)[source]#

Delete Comments based on filters

Parameters:

filters (dict) – similar to QueryBuilder filter

Returns:

(former) PK s of deleted Comments

Return type:

list

Raises:

SqlAlchemy implementations for the Computer entity and collection.

class aiida.storage.psql_dos.orm.computers.SqlaComputer(backend, **kwargs)[source]#

Bases: SqlaModelEntity[DbComputer], BackendComputer

SqlAlchemy implementation for BackendComputer.

MODEL_CLASS#

alias of DbComputer

__abstractmethods__ = frozenset({})#
__init__(backend, **kwargs)[source]#
__module__ = 'aiida.storage.psql_dos.orm.computers'#
__orig_bases__ = (aiida.storage.psql_dos.orm.entities.SqlaModelEntity[aiida.storage.psql_dos.models.computer.DbComputer], <class 'aiida.orm.implementation.computers.BackendComputer'>)#
__parameters__ = ()#
_abc_impl = <_abc._abc_data object>#
_model: ModelWrapper#
copy()[source]#

Create an unstored clone of an already stored Computer.

property description#

Return the description of the computer.

get_metadata()[source]#

Return the metadata for the computer.

get_scheduler_type()[source]#

Return the scheduler plugin type.

get_transport_type()[source]#

Return the transport plugin type.

property hostname#

Return the hostname of the computer (used to associate the connected device).

property id#

Get the id of this entity

Returns:

the entity id

property is_stored#

Is this entity stored?

Returns:

True if stored, False otherwise

property label#

Return the (unique) label of the computer.

property pk#

Return the id for this entity.

This is unique only amongst entities of this type for a particular backend.

Returns:

the entity id

set_description(val)[source]#

Set the description of the computer.

set_hostname(val)[source]#

Set the hostname of this computer :param val: The new hostname

set_label(val)[source]#

Set the (unique) label of the computer.

set_metadata(metadata)[source]#

Set the metadata for the computer.

set_scheduler_type(scheduler_type)[source]#

Set the scheduler plugin type.

set_transport_type(transport_type)[source]#

Set the transport plugin type.

store()[source]#

Store the Computer instance.

property uuid#

Return the UUID of the computer.

class aiida.storage.psql_dos.orm.computers.SqlaComputerCollection(backend: StorageBackend)[source]#

Bases: BackendComputerCollection

Collection of Computer instances.

ENTITY_CLASS#

alias of SqlaComputer

__annotations__ = {}#
__module__ = 'aiida.storage.psql_dos.orm.computers'#
__parameters__ = ()#
delete(pk)[source]#

Delete an entry with the given pk

Parameters:

pk – the pk of the entry to delete

list_names()[source]#

Module to get the backend instance from the Models instance

aiida.storage.psql_dos.orm.convert._(dbmodel, backend)[source]#

Convert a dblink to the backend entity

aiida.storage.psql_dos.orm.convert.get_backend_entity(dbmodel, backend)[source]#
aiida.storage.psql_dos.orm.convert.get_backend_entity(dbmodel: DbUser, backend)
aiida.storage.psql_dos.orm.convert.get_backend_entity(dbmodel: DbGroup, backend)
aiida.storage.psql_dos.orm.convert.get_backend_entity(dbmodel: DbComputer, backend)
aiida.storage.psql_dos.orm.convert.get_backend_entity(dbmodel: DbNode, backend)
aiida.storage.psql_dos.orm.convert.get_backend_entity(dbmodel: DbAuthInfo, backend)
aiida.storage.psql_dos.orm.convert.get_backend_entity(dbmodel: DbComment, backend)
aiida.storage.psql_dos.orm.convert.get_backend_entity(dbmodel: DbLog, backend)
aiida.storage.psql_dos.orm.convert.get_backend_entity(dbmodel: DbLink, backend)

Default get_backend_entity

Classes and methods for Django specific backend entities

class aiida.storage.psql_dos.orm.entities.SqlaModelEntity(*args, **kwargs)[source]#

Bases: Generic[ModelType]

A mixin that adds some common SQLA backend entity methods

MODEL_CLASS = None#
__annotations__ = {'_model': <class 'aiida.storage.psql_dos.orm.utils.ModelWrapper'>}#
__dict__ = mappingproxy({'__module__': 'aiida.storage.psql_dos.orm.entities', '__annotations__': {'_model': <class 'aiida.storage.psql_dos.orm.utils.ModelWrapper'>}, '__doc__': 'A mixin that adds some common SQLA backend entity methods', 'MODEL_CLASS': None, '_class_check': <classmethod(<function SqlaModelEntity._class_check>)>, 'from_dbmodel': <classmethod(<function SqlaModelEntity.from_dbmodel>)>, '__init__': <function SqlaModelEntity.__init__>, 'model': <property object>, 'bare_model': <property object>, 'id': <property object>, 'is_stored': <property object>, 'store': <function SqlaModelEntity.store>, '_flush_if_stored': <function SqlaModelEntity._flush_if_stored>, '__orig_bases__': (typing.Generic[~ModelType],), '__dict__': <attribute '__dict__' of 'SqlaModelEntity' objects>, '__weakref__': <attribute '__weakref__' of 'SqlaModelEntity' objects>, '__parameters__': (~ModelType,)})#
__init__(*args, **kwargs)[source]#
__module__ = 'aiida.storage.psql_dos.orm.entities'#
__orig_bases__ = (typing.Generic[~ModelType],)#
__parameters__ = (~ModelType,)#
__weakref__#

list of weak references to the object (if defined)

classmethod _class_check()[source]#

Assert that the class is correctly configured

_flush_if_stored(fields: Set[str]) None[source]#
_model: ModelWrapper#
property bare_model#

Return the underlying SQLA ORM model for this entity.

Warning

Getting/setting attributes on this model bypasses AiiDA’s internal update/flush mechanisms.

classmethod from_dbmodel(dbmodel, backend)[source]#

Create an AiiDA Entity from the corresponding SQLA ORM model and storage backend

Parameters:
  • dbmodel – the SQLAlchemy model to create the entity from

  • backend – the corresponding storage backend

Returns:

the AiiDA entity

property id: int#

Get the id of this entity

Returns:

the entity id

property is_stored: bool#

Is this entity stored?

Returns:

True if stored, False otherwise

property model: ModelWrapper#

Return an ORM model that correctly updates and flushes the data when getting or setting a field.

store() SelfType[source]#

Store this entity

Returns:

the entity itself

Mixin class for SQL implementations of extras.

class aiida.storage.psql_dos.orm.extras_mixin.ExtrasMixin[source]#

Bases: object

Mixin class for SQL implementations of extras.

__annotations__ = {'bare_model': typing.Any, 'is_stored': <class 'bool'>, 'model': typing.Any}#
__dict__ = mappingproxy({'__module__': 'aiida.storage.psql_dos.orm.extras_mixin', '__annotations__': {'model': typing.Any, 'bare_model': typing.Any, 'is_stored': <class 'bool'>}, '__doc__': 'Mixin class for SQL implementations of ``extras``.', 'extras': <property object>, 'get_extra': <function ExtrasMixin.get_extra>, 'set_extra': <function ExtrasMixin.set_extra>, 'set_extra_many': <function ExtrasMixin.set_extra_many>, 'reset_extras': <function ExtrasMixin.reset_extras>, 'delete_extra': <function ExtrasMixin.delete_extra>, 'delete_extra_many': <function ExtrasMixin.delete_extra_many>, 'clear_extras': <function ExtrasMixin.clear_extras>, 'extras_items': <function ExtrasMixin.extras_items>, 'extras_keys': <function ExtrasMixin.extras_keys>, '__dict__': <attribute '__dict__' of 'ExtrasMixin' objects>, '__weakref__': <attribute '__weakref__' of 'ExtrasMixin' objects>})#
__module__ = 'aiida.storage.psql_dos.orm.extras_mixin'#
__weakref__#

list of weak references to the object (if defined)

bare_model: Any#
clear_extras() None[source]#
delete_extra(key: str) None[source]#
delete_extra_many(keys: Iterable[str]) None[source]#
property extras: Dict[str, Any]#
extras_items() Iterable[Tuple[str, Any]][source]#
extras_keys() Iterable[str][source]#
get_extra(key: str) Any[source]#
is_stored: bool#
model: Any#
reset_extras(extras: Dict[str, Any]) None[source]#
set_extra(key: str, value: Any) None[source]#
set_extra_many(extras: Dict[str, Any]) None[source]#

SQLA groups

class aiida.storage.psql_dos.orm.groups.SqlaGroup(backend, label, user, description='', type_string='')[source]#

Bases: SqlaModelEntity[DbGroup], ExtrasMixin, BackendGroup

The SQLAlchemy Group object

GROUP_NODE_CLASS#

alias of DbGroupNode

MODEL_CLASS#

alias of DbGroup

NODE_CLASS#

alias of SqlaNode

USER_CLASS#

alias of SqlaUser

__abstractmethods__ = frozenset({})#
__init__(backend, label, user, description='', type_string='')[source]#

Construct a new SQLA group

Parameters:
  • backend – the backend to use

  • label – the group label

  • user – the owner of the group

  • description – an optional group description

  • type_string – an optional type for the group to contain

__module__ = 'aiida.storage.psql_dos.orm.groups'#
__orig_bases__ = (aiida.storage.psql_dos.orm.entities.SqlaModelEntity[aiida.storage.psql_dos.models.group.DbGroup], <class 'aiida.storage.psql_dos.orm.extras_mixin.ExtrasMixin'>, <class 'aiida.orm.implementation.groups.BackendGroup'>)#
__parameters__ = ()#
_abc_impl = <_abc._abc_data object>#
_model: ModelWrapper#
add_nodes(nodes, **kwargs)[source]#

Add a node or a set of nodes to the group.

Note:

all the nodes and the group itself have to be stored.

Parameters:
  • nodes – a list of BackendNode instance to be added to this group

  • kwargs – skip_orm: When the flag is on, the SQLA ORM is skipped and SQLA is used to create a direct SQL INSERT statement to the group-node relationship table (to improve speed).

clear()[source]#

Remove all the nodes from this group.

count()[source]#

Return the number of entities in this group.

Returns:

integer number of entities contained within the group

property description#

Return the description of the group as a string.

property is_stored#

Is this entity stored?

Returns:

True if stored, False otherwise

property label#

Return the name of the group as a string.

property nodes#

Get an iterator to all the nodes in the group

property pk#

Return the id for this entity.

This is unique only amongst entities of this type for a particular backend.

Returns:

the entity id

remove_nodes(nodes, **kwargs)[source]#

Remove a node or a set of nodes from the group.

Note:

all the nodes and the group itself have to be stored.

Parameters:
  • nodes – a list of BackendNode instance to be added to this group

  • kwargs – skip_orm: When the flag is set to True, the SQLA ORM is skipped and SQLA is used to create a direct SQL DELETE statement to the group-node relationship table in order to improve speed.

store()[source]#

Store this entity

Returns:

the entity itself

property type_string#

Return the string defining the type of the group.

property user#

Return a backend user object, representing the user associated to this group.

property uuid#

Return the UUID of the group.

class aiida.storage.psql_dos.orm.groups.SqlaGroupCollection(backend: StorageBackend)[source]#

Bases: BackendGroupCollection

The SLQA collection of groups

ENTITY_CLASS#

alias of SqlaGroup

__annotations__ = {}#
__module__ = 'aiida.storage.psql_dos.orm.groups'#
__parameters__ = ()#
delete(id)[source]#

Delete a group with the given id

Parameters:

id – the id of the group to delete

SQLA Log and LogCollection module

class aiida.storage.psql_dos.orm.logs.SqlaLog(backend, time, loggername, levelname, dbnode_id, message='', metadata=None)[source]#

Bases: SqlaModelEntity[DbLog], BackendLog

SQLA Log backend entity

MODEL_CLASS#

alias of DbLog

__abstractmethods__ = frozenset({})#
__init__(backend, time, loggername, levelname, dbnode_id, message='', metadata=None)[source]#
__module__ = 'aiida.storage.psql_dos.orm.logs'#
__orig_bases__ = (aiida.storage.psql_dos.orm.entities.SqlaModelEntity[aiida.storage.psql_dos.models.log.DbLog], <class 'aiida.orm.implementation.logs.BackendLog'>)#
__parameters__ = ()#
_abc_impl = <_abc._abc_data object>#
_model: ModelWrapper#
property dbnode_id#

Get the id of the object that created the log entry

property levelname#

The name of the log level

property loggername#

The name of the logger that created this entry

property message#

Get the message corresponding to the entry

property metadata#

Get the metadata corresponding to the entry

property time#

Get the time corresponding to the entry

property uuid#

Get the string representation of the UUID of the log entry

class aiida.storage.psql_dos.orm.logs.SqlaLogCollection(backend: StorageBackend)[source]#

Bases: BackendLogCollection

The SQLA collection for logs

ENTITY_CLASS#

alias of SqlaLog

__annotations__ = {}#
__module__ = 'aiida.storage.psql_dos.orm.logs'#
__parameters__ = ()#
delete(log_id)[source]#

Remove a Log entry from the collection with the given id

Parameters:

log_id (int) – id of the Log to delete

Raises:
delete_all()[source]#

Delete all Log entries.

Raises:

IntegrityError – if all Logs could not be deleted

delete_many(filters)[source]#

Delete Logs based on filters

Parameters:

filters (dict) – similar to QueryBuilder filter

Returns:

(former) PK s of deleted Logs

Return type:

list

Raises:

SqlAlchemy implementation of the BackendNode and BackendNodeCollection classes.

class aiida.storage.psql_dos.orm.nodes.SqlaNode(backend, node_type, user, computer=None, process_type=None, label='', description='', ctime=None, mtime=None)[source]#

Bases: SqlaModelEntity[DbNode], ExtrasMixin, BackendNode

SQLA Node backend entity

COMPUTER_CLASS#

alias of SqlaComputer

alias of DbLink

MODEL_CLASS#

alias of DbNode

USER_CLASS#

alias of SqlaUser

__abstractmethods__ = frozenset({})#
__init__(backend, node_type, user, computer=None, process_type=None, label='', description='', ctime=None, mtime=None)[source]#

Construct a new BackendNode instance wrapping a new DbNode instance.

Parameters:
  • backend – the backend

  • node_type – the node type string

  • user – associated BackendUser

  • computer – associated BackendComputer

  • label – string label

  • description – string description

  • ctime – The creation time as datetime object

  • mtime – The modification time as datetime object

__module__ = 'aiida.storage.psql_dos.orm.nodes'#
__orig_bases__ = (aiida.storage.psql_dos.orm.entities.SqlaModelEntity[aiida.storage.psql_dos.models.node.DbNode], <class 'aiida.storage.psql_dos.orm.extras_mixin.ExtrasMixin'>, <class 'aiida.orm.implementation.nodes.BackendNode'>)#
__parameters__ = ()#
_abc_impl = <_abc._abc_data object>#

Add a single link

_model: ModelWrapper#
add_incoming(source, link_type, link_label)[source]#

Add a link of the given type from a given node to ourself.

Parameters:
  • source – the node from which the link is coming

  • link_type – the link type

  • link_label – the link label

Returns:

True if the proposed link is allowed, False otherwise

Raises:
property attributes#

Return the complete attributes dictionary.

Warning

While the entity is unstored, this will return references of the attributes on the database model, meaning that changes on the returned values (if they are mutable themselves, e.g. a list or dictionary) will automatically be reflected on the database model as well. As soon as the entity is stored, the returned attributes will be a deep copy and mutations of the database attributes will have to go through the appropriate set methods. Therefore, once stored, retrieving a deep copy can be a heavy operation. If you only need the keys or some values, use the iterators attributes_keys and attributes_items, or the getters get_attribute and get_attribute_many instead.

Returns:

the attributes as a dictionary

attributes_items() Iterable[Tuple[str, Any]][source]#

Return an iterator over the attributes.

Returns:

an iterator with attribute key value pairs

attributes_keys() Iterable[str][source]#

Return an iterator over the attribute keys.

Returns:

an iterator with attribute keys

clean_values()[source]#

Clean the values of the node fields.

This method is called before storing the node. The purpose of this method is to convert data to a type which can be serialized and deserialized for storage in the DB without its value changing.

clear_attributes()[source]#

Delete all attributes.

clone()[source]#

Return an unstored clone of ourselves.

Returns:

an unstored BackendNode with the exact same attributes and extras as self

property computer#

Return the computer of this node.

Returns:

the computer or None

property ctime#

Return the node ctime.

Returns:

the ctime

delete_attribute(key: str) None[source]#

Delete an attribute.

Parameters:

key – name of the attribute

Raises:

AttributeError – if the attribute does not exist

delete_attribute_many(keys: Iterable[str]) None[source]#

Delete multiple attributes.

Parameters:

keys – names of the attributes to delete

Raises:

AttributeError – if at least one of the attribute does not exist

property description#

Return the node description.

Returns:

the description

get_attribute(key: str) Any[source]#

Return the value of an attribute.

Warning

While the entity is unstored, this will return a reference of the attribute on the database model, meaning that changes on the returned value (if they are mutable themselves, e.g. a list or dictionary) will automatically be reflected on the database model as well. As soon as the entity is stored, the returned attribute will be a deep copy and mutations of the database attributes will have to go through the appropriate set methods.

Parameters:

key – name of the attribute

Returns:

the value of the attribute

Raises:

AttributeError – if the attribute does not exist

property label#

Return the node label.

Returns:

the label

property mtime#

Return the node mtime.

Returns:

the mtime

property node_type#

Return the node type.

Returns:

the node type

property process_type#

Return the node process type.

Returns:

the process type

property repository_metadata#

Return the node repository metadata.

Returns:

the repository metadata

reset_attributes(attributes: Dict[str, Any]) None[source]#

Reset the attributes.

Note

This will completely clear any existing attributes and replace them with the new dictionary.

Parameters:

attributes – a dictionary with the attributes to set

set_attribute(key: str, value: Any) None[source]#

Set an attribute to the given value.

Parameters:
  • key – name of the attribute

  • value – value of the attribute

set_attribute_many(attributes: Dict[str, Any]) None[source]#

Set multiple attributes.

Note

This will override any existing attributes that are present in the new dictionary.

Parameters:

attributes – a dictionary with the attributes to set

store(links=None, clean=True)[source]#

Store this entity

Returns:

the entity itself

property user#

Return the user of this node.

Returns:

the user

property uuid#

Return the node UUID.

Returns:

the string representation of the UUID

class aiida.storage.psql_dos.orm.nodes.SqlaNodeCollection(backend: StorageBackend)[source]#

Bases: BackendNodeCollection

The collection of Node entries.

ENTITY_CLASS#

alias of SqlaNode

__annotations__ = {'ENTITY_CLASS': typing.Type[aiida.storage.psql_dos.orm.nodes.SqlaNode]}#
__module__ = 'aiida.storage.psql_dos.orm.nodes'#
__parameters__ = ()#
delete(pk)[source]#

Remove a Node entry from the collection with the given id

Parameters:

pk – id of the node to delete

get(pk)[source]#

Return a Node entry from the collection with the given id

Parameters:

pk – id of the node

SQLA user

class aiida.storage.psql_dos.orm.users.SqlaUser(backend, email, first_name, last_name, institution)[source]#

Bases: SqlaModelEntity[DbUser], BackendUser

SQLA user

MODEL_CLASS#

alias of DbUser

__abstractmethods__ = frozenset({})#
__init__(backend, email, first_name, last_name, institution)[source]#
__module__ = 'aiida.storage.psql_dos.orm.users'#
__orig_bases__ = (aiida.storage.psql_dos.orm.entities.SqlaModelEntity[aiida.storage.psql_dos.models.user.DbUser], <class 'aiida.orm.implementation.users.BackendUser'>)#
__parameters__ = ()#
_abc_impl = <_abc._abc_data object>#
_model: ModelWrapper#
property email#

Get the email address of the user

Returns:

the email address

property first_name#

Get the user’s first name

Returns:

the first name

property institution#

Get the user’s institution

Returns:

the institution

property last_name#

Get the user’s last name

Returns:

the last name

class aiida.storage.psql_dos.orm.users.SqlaUserCollection(backend: StorageBackend)[source]#

Bases: BackendUserCollection

Collection of SQLA Users

ENTITY_CLASS#

alias of SqlaUser

__annotations__ = {}#
__module__ = 'aiida.storage.psql_dos.orm.users'#
__parameters__ = ()#
create(email, first_name='', last_name='', institution='')[source]#

Create a user with the provided email address

Utilities for the implementation of the SqlAlchemy backend.

class aiida.storage.psql_dos.orm.utils.ModelWrapper(model, backend: PsqlDosBackend)[source]#

Bases: object

Wrap an SQLA ORM model and AiiDA storage backend instance together, to correctly update and flush the data model when getting or setting a field.

The ORM model represents a row in a database table, with a given schema, and its attributes represent the fields (a.k.a. columns) of the table. When an ORM model instance is created, it does not have any association with a particular database, i.e. it is “unsaved”. At this point, its attributes can be freely retrieved or set.

When the ORM model instance is saved, it is associated with the database configured for the backend instance, by adding it to the backend instances’s session (i.e. its connection with the database). At this point:

  • Whenever we retrieve a field of the model instance, unless we know it to be immutable, we first ensure that the field represents the latest value in the database (e.g. in case the database has been externally updated).

  • Whenever we set a field of the model instance, unless we know it to be immutable, we flush the change to the database.

__dict__ = mappingproxy({'__module__': 'aiida.storage.psql_dos.orm.utils', '__doc__': 'Wrap an SQLA ORM model and AiiDA storage backend instance together,\n    to correctly update and flush the data model when getting or setting a field.\n\n    The ORM model represents a row in a database table, with a given schema,\n    and its attributes represent the fields (a.k.a. columns) of the table.\n    When an ORM model instance is created, it does not have any association with a particular database,\n    i.e. it is "unsaved".\n    At this point, its attributes can be freely retrieved or set.\n\n    When the ORM model instance is saved, it is associated with the database configured for the backend instance,\n    by adding it to the backend instances\'s session (i.e. its connection with the database).\n    At this point:\n\n    - Whenever we retrieve a field of the model instance, unless we know it to be immutable,\n      we first ensure that the field represents the latest value in the database\n      (e.g. in case the database has been externally updated).\n\n    - Whenever we set a field of the model instance, unless we know it to be immutable,\n      we flush the change to the database.\n\n    ', '__init__': <function ModelWrapper.__init__>, 'session': <property object>, '__getattr__': <function ModelWrapper.__getattr__>, '__setattr__': <function ModelWrapper.__setattr__>, 'is_saved': <function ModelWrapper.is_saved>, 'save': <function ModelWrapper.save>, '_is_mutable_model_field': <function ModelWrapper._is_mutable_model_field>, '_is_model_field': <function ModelWrapper._is_model_field>, '_flush': <function ModelWrapper._flush>, '_ensure_model_uptodate': <function ModelWrapper._ensure_model_uptodate>, '_in_transaction': <function ModelWrapper._in_transaction>, '__dict__': <attribute '__dict__' of 'ModelWrapper' objects>, '__weakref__': <attribute '__weakref__' of 'ModelWrapper' objects>, '__annotations__': {}})#
__getattr__(item)[source]#

Get an attribute of the model instance.

If the model is saved in the database, the item corresponds to a mutable model field and the current scope is not in an open database connection, then the field’s value is first refreshed from the database.

Parameters:

item – the name of the model field

Returns:

the value of the model’s attribute

__init__(model, backend: PsqlDosBackend)[source]#

Construct the ModelWrapper.

Parameters:
  • model – the ORM model instance to wrap

  • backend – the storage backend instance

__module__ = 'aiida.storage.psql_dos.orm.utils'#
__setattr__(key, value)[source]#

Set the attribute on the model instance.

If the field being set is a mutable model field and the model is saved, the changes are flushed.

Parameters:
  • key – the name of the model field

  • value – the value to set

__weakref__#

list of weak references to the object (if defined)

_ensure_model_uptodate(fields=None)[source]#

Refresh all fields of the wrapped model instance by fetching the current state of the database instance.

Parameters:

fields – optionally refresh only these fields, if None all fields are refreshed.

_flush(fields=())[source]#

Flush the fields of the model to the database.

Note

If the wrapped model is not actually saved in the database yet, this method is a no-op.

Parameters:

fields – the model fields whose current value to flush to the database

_in_transaction()[source]#

Return whether the current scope is within an open database transaction.

Returns:

boolean, True if currently in open transaction, False otherwise.

_is_model_field(field)[source]#

Return whether the field is a field of the model.

Returns:

boolean, True if the field is a model field, False otherwise.

_is_mutable_model_field(field)[source]#

Return whether the field is a mutable field of the model.

Returns:

boolean, True if the field is a model field and is not in the IMMUTABLE_MODEL_FIELDS set.

is_saved()[source]#

Return whether the wrapped model instance is saved in the database.

Returns:

boolean, True if the model is saved in the database, False otherwise

save()[source]#

Store the model instance.

Note

If one is currently in a transaction, this method is a no-op.

Raises:

aiida.common.IntegrityError – if a database integrity error is raised during the save.

property session: Session#

Return the session of the storage backend instance.

aiida.storage.psql_dos.orm.utils.disable_expire_on_commit(session)[source]#

Context manager that disables expire_on_commit and restores the original value on exit

Parameters:

session (sqlalchemy.orm.session.Session) – The SQLA session