aiida.storage.psql_dos.orm package#
Implementation of ORM backend entities.
Subpackages#
- aiida.storage.psql_dos.orm.querybuilder package
- Submodules
JoinReturn
JoinReturn.__annotations__
JoinReturn.__dataclass_fields__
JoinReturn.__dataclass_params__
JoinReturn.__dict__
JoinReturn.__eq__()
JoinReturn.__hash__
JoinReturn.__init__()
JoinReturn.__match_args__
JoinReturn.__module__
JoinReturn.__repr__()
JoinReturn.__weakref__
JoinReturn.aliased_edge
JoinReturn.edge_tag
JoinReturn.join
SqlaJoiner
SqlaJoiner.__dict__
SqlaJoiner.__init__()
SqlaJoiner.__module__
SqlaJoiner.__weakref__
SqlaJoiner._entity_join_map()
SqlaJoiner._join_authinfo_user()
SqlaJoiner._join_comment_node()
SqlaJoiner._join_comment_user()
SqlaJoiner._join_computer_authinfo()
SqlaJoiner._join_computer_node()
SqlaJoiner._join_group_node()
SqlaJoiner._join_group_user()
SqlaJoiner._join_log_node()
SqlaJoiner._join_node_ancestors_recursive()
SqlaJoiner._join_node_comment()
SqlaJoiner._join_node_computer()
SqlaJoiner._join_node_descendants_recursive()
SqlaJoiner._join_node_group()
SqlaJoiner._join_node_inputs()
SqlaJoiner._join_node_log()
SqlaJoiner._join_node_outputs()
SqlaJoiner._join_node_user()
SqlaJoiner._join_user_authinfo()
SqlaJoiner._join_user_comment()
SqlaJoiner._join_user_group()
SqlaJoiner._join_user_node()
SqlaJoiner.get_join_func()
_EntityMapper
_EntityMapper.AuthInfo
_EntityMapper.Comment
_EntityMapper.Computer
_EntityMapper.Group
_EntityMapper.Link
_EntityMapper.Log
_EntityMapper.Node
_EntityMapper.User
_EntityMapper.__abstractmethods__
_EntityMapper.__dict__
_EntityMapper.__init__()
_EntityMapper.__module__
_EntityMapper.__parameters__
_EntityMapper.__subclasshook__()
_EntityMapper.__weakref__
_EntityMapper._abc_impl
_EntityMapper._is_protocol
_EntityMapper.table_groups_nodes
_check_dbentities()
BuiltQuery
BuiltQuery.__annotations__
BuiltQuery.__dataclass_fields__
BuiltQuery.__dataclass_params__
BuiltQuery.__dict__
BuiltQuery.__eq__()
BuiltQuery.__hash__
BuiltQuery.__init__()
BuiltQuery.__match_args__
BuiltQuery.__module__
BuiltQuery.__repr__()
BuiltQuery.__weakref__
BuiltQuery.query
BuiltQuery.tag_to_alias
BuiltQuery.tag_to_projected
SqlaQueryBuilder
SqlaQueryBuilder.AuthInfo
SqlaQueryBuilder.Comment
SqlaQueryBuilder.Computer
SqlaQueryBuilder.Group
SqlaQueryBuilder.Link
SqlaQueryBuilder.Log
SqlaQueryBuilder.Node
SqlaQueryBuilder.User
SqlaQueryBuilder.__abstractmethods__
SqlaQueryBuilder.__init__()
SqlaQueryBuilder.__module__
SqlaQueryBuilder._abc_impl
SqlaQueryBuilder._build()
SqlaQueryBuilder._create_order_by()
SqlaQueryBuilder._get_projectable_entity()
SqlaQueryBuilder.analyze_query()
SqlaQueryBuilder.as_sql()
SqlaQueryBuilder.build_filters()
SqlaQueryBuilder.count()
SqlaQueryBuilder.first()
SqlaQueryBuilder.get_creation_statistics()
SqlaQueryBuilder.get_filter_expr()
SqlaQueryBuilder.get_filter_expr_from_column()
SqlaQueryBuilder.get_filter_expr_from_jsonb()
SqlaQueryBuilder.get_query()
SqlaQueryBuilder.get_session()
SqlaQueryBuilder.iterall()
SqlaQueryBuilder.iterdict()
SqlaQueryBuilder.query_session()
SqlaQueryBuilder.table_groups_nodes
SqlaQueryBuilder.to_backend()
_create_projections()
_get_projection()
compile_query()
generate_joins()
generate_projections()
get_column()
get_column_names()
get_corresponding_properties()
get_corresponding_property()
get_table_name()
modify_expansions()
- Submodules
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
- __abstractmethods__ = frozenset({})#
- __init__(backend, computer, user)[source]#
Construct a new instance.
- Parameters:
computer – a
aiida.orm.implementation.computers.BackendComputer
instanceuser – a
aiida.orm.implementation.users.BackendUser
instance
- 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.
- 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
- 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.
- 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__ = ()#
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.
- __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.
- property user#
Return the comment owner.
- 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 intNotExistent – 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
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({})#
- __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#
- property description#
Return the description of the computer.
- 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
- 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__ = ()#
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,)})#
- __module__ = 'aiida.storage.psql_dos.orm.entities'#
- __orig_bases__ = (typing.Generic[~ModelType],)#
- __parameters__ = (~ModelType,)#
- __weakref__#
list of weak references to the object
- _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 model: ModelWrapper#
Return an ORM model that correctly updates and flushes the data when getting or setting a field.
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
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
- __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).
- 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.
- 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
- __annotations__ = {}#
- __module__ = 'aiida.storage.psql_dos.orm.groups'#
- __parameters__ = ()#
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
- __abstractmethods__ = frozenset({})#
- __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
- __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:
TypeError – if
log_id
is not an intNotExistent – if Log with ID
log_id
is not found
- delete_all()[source]#
Delete all Log entries.
- Raises:
IntegrityError – if all Logs could not be deleted
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
- __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>#
- _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:
TypeError – if source is not a Node instance or link_type is not a LinkType enum
ValueError – if the proposed link is invalid
aiida.common.ModificationNotAllowed – if either source or target node is not stored
- 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.
- 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
- 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.
- __annotations__ = {'ENTITY_CLASS': typing.Type[aiida.storage.psql_dos.orm.nodes.SqlaNode]}#
- __module__ = 'aiida.storage.psql_dos.orm.nodes'#
- __parameters__ = ()#
SQLA user
- class aiida.storage.psql_dos.orm.users.SqlaUser(backend, email, first_name, last_name, institution)[source]#
Bases:
SqlaModelEntity
[DbUser
],BackendUser
SQLA user
- __abstractmethods__ = frozenset({})#
- __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
- __annotations__ = {}#
- __module__ = 'aiida.storage.psql_dos.orm.users'#
- __parameters__ = ()#
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
- _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.
- 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