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)[源代码]#

基类:SqlaModelEntity[DbAuthInfo], BackendAuthInfo

SqlAlchemy backend implementation for the AuthInfo ORM class.

COMPUTER_CLASS#

SqlaComputer 的别名

MODEL_CLASS#

DbAuthInfo 的别名

USER_CLASS#

SqlaUser 的别名

__abstractmethods__ = frozenset({})#
__init__(backend, computer, user)[源代码]#

Construct a new instance.

参数:
返回:

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.

返回:

aiida.orm.implementation.computers.BackendComputer

property enabled: bool#

Return whether this instance is enabled.

返回:

boolean, True if enabled, False otherwise

get_auth_params()[源代码]#

Return the dictionary of authentication parameters

返回:

a dictionary with authentication parameters

get_metadata()[源代码]#

Return the dictionary of metadata

返回:

a dictionary with metadata

property id#

Get the id of this entity

返回:

the entity id

property is_stored: bool#

Return whether the entity is stored.

返回:

True if stored, False otherwise

set_auth_params(auth_params)[源代码]#

Set the dictionary of authentication parameters

参数:

auth_params – a dictionary with authentication parameters

set_metadata(metadata)[源代码]#

Set the dictionary of metadata

参数:

metadata – a dictionary with metadata

property user#

Return the user associated with this instance.

返回:

aiida.orm.implementation.users.BackendUser

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

基类:BackendAuthInfoCollection

The collection of SqlAlchemy backend AuthInfo entries.

ENTITY_CLASS#

SqlaAuthInfo 的别名

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

Delete an entry from the collection.

参数:

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)[源代码]#

基类:SqlaModelEntity[DbComment], BackendComment

Comment implementation for Sqla.

MODEL_CLASS#

DbComment 的别名

USER_CLASS#

SqlaUser 的别名

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

Construct a SqlaComment.

参数:
  • 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)[源代码]#

Set the comment content.

set_mtime(value)[源代码]#

Set the modified time of the comment.

set_user(value)[源代码]#

Set the comment owner.

store()[源代码]#

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)[源代码]#

基类:BackendCommentCollection

SqlAlchemy implementation for the CommentCollection.

ENTITY_CLASS#

SqlaComment 的别名

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

Create a Comment for a given node and user

参数:
  • node – a Node instance

  • user – a User instance

  • content – the comment content

返回:

a Comment object associated to the given node and user

delete(comment_id)[源代码]#

Remove a Comment from the collection with the given id

参数:

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

抛出:
  • TypeError – if comment_id is not an int

  • NotExistent – if Comment with ID comment_id is not found

delete_all()[源代码]#

Delete all Comment entries.

抛出:

IntegrityError – if all Comments could not be deleted

delete_many(filters)[源代码]#

Delete Comments based on filters

参数:

filters (dict) – similar to QueryBuilder filter

返回:

(former) PK s of deleted Comments

返回类型:

list

抛出:

SqlAlchemy implementations for the Computer entity and collection.

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

基类:SqlaModelEntity[DbComputer], BackendComputer

SqlAlchemy implementation for BackendComputer.

MODEL_CLASS#

DbComputer 的别名

__abstractmethods__ = frozenset({})#
__init__(backend, **kwargs)[源代码]#
__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()[源代码]#

Create an unstored clone of an already stored Computer.

property description#

Return the description of the computer.

get_metadata()[源代码]#

Return the metadata for the computer.

get_scheduler_type()[源代码]#

Return the scheduler plugin type.

get_transport_type()[源代码]#

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

返回:

the entity id

property is_stored#

Is this entity stored?

返回:

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.

返回:

the entity id

set_description(val)[源代码]#

Set the description of the computer.

set_hostname(val)[源代码]#

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

set_label(val)[源代码]#

Set the (unique) label of the computer.

set_metadata(metadata)[源代码]#

Set the metadata for the computer.

set_scheduler_type(scheduler_type)[源代码]#

Set the scheduler plugin type.

set_transport_type(transport_type)[源代码]#

Set the transport plugin type.

store()[源代码]#

Store the Computer instance.

property uuid#

Return the UUID of the computer.

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

基类:BackendComputerCollection

Collection of Computer instances.

ENTITY_CLASS#

SqlaComputer 的别名

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

Delete an entry with the given pk

参数:

pk – the pk of the entry to delete

list_names()[源代码]#

Module to get the backend instance from the Models instance

aiida.storage.psql_dos.orm.convert._(dbmodel, backend)[源代码]#

Convert a dblink to the backend entity

aiida.storage.psql_dos.orm.convert.get_backend_entity(dbmodel, backend)[源代码]#
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)[源代码]#

基类: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)[源代码]#
__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()[源代码]#

Assert that the class is correctly configured

_flush_if_stored(fields: Set[str]) None[源代码]#
_model: ModelWrapper#
property bare_model#

Return the underlying SQLA ORM model for this entity.

警告

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

classmethod from_dbmodel(dbmodel, backend)[源代码]#

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

参数:
  • dbmodel – the SQLAlchemy model to create the entity from

  • backend – the corresponding storage backend

返回:

the AiiDA entity

property id: int#

Get the id of this entity

返回:

the entity id

property is_stored: bool#

Is this entity stored?

返回:

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[源代码]#

Store this entity

返回:

the entity itself

Mixin class for SQL implementations of extras.

class aiida.storage.psql_dos.orm.extras_mixin.ExtrasMixin[源代码]#

基类: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[源代码]#
delete_extra(key: str) None[源代码]#
delete_extra_many(keys: Iterable[str]) None[源代码]#
property extras: Dict[str, Any]#
extras_items() Iterable[Tuple[str, Any]][源代码]#
extras_keys() Iterable[str][源代码]#
get_extra(key: str) Any[源代码]#
is_stored: bool#
model: Any#
reset_extras(extras: Dict[str, Any]) None[源代码]#
set_extra(key: str, value: Any) None[源代码]#
set_extra_many(extras: Dict[str, Any]) None[源代码]#

SQLA groups

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

基类:SqlaModelEntity[DbGroup], ExtrasMixin, BackendGroup

The SQLAlchemy Group object

GROUP_NODE_CLASS#

DbGroupNode 的别名

MODEL_CLASS#

DbGroup 的别名

NODE_CLASS#

SqlaNode 的别名

USER_CLASS#

SqlaUser 的别名

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

Construct a new SQLA group

参数:
  • 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)[源代码]#

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

Note:

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

参数:
  • 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()[源代码]#

Remove all the nodes from this group.

count()[源代码]#

Return the number of entities in this group.

返回:

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?

返回:

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.

返回:

the entity id

remove_nodes(nodes, **kwargs)[源代码]#

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

Note:

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

参数:
  • 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()[源代码]#

Store this entity

返回:

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)[源代码]#

基类:BackendGroupCollection

The SLQA collection of groups

ENTITY_CLASS#

SqlaGroup 的别名

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

Delete a group with the given id

参数:

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)[源代码]#

基类:SqlaModelEntity[DbLog], BackendLog

SQLA Log backend entity

MODEL_CLASS#

DbLog 的别名

__abstractmethods__ = frozenset({})#
__init__(backend, time, loggername, levelname, dbnode_id, message='', metadata=None)[源代码]#
__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)[源代码]#

基类:BackendLogCollection

The SQLA collection for logs

ENTITY_CLASS#

SqlaLog 的别名

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

Remove a Log entry from the collection with the given id

参数:

log_id (int) – id of the Log to delete

抛出:
delete_all()[源代码]#

Delete all Log entries.

抛出:

IntegrityError – if all Logs could not be deleted

delete_many(filters)[源代码]#

Delete Logs based on filters

参数:

filters (dict) – similar to QueryBuilder filter

返回:

(former) PK s of deleted Logs

返回类型:

list

抛出:

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)[源代码]#

基类:SqlaModelEntity[DbNode], ExtrasMixin, BackendNode

SQLA Node backend entity

COMPUTER_CLASS#

SqlaComputer 的别名

DbLink 的别名

MODEL_CLASS#

DbNode 的别名

USER_CLASS#

SqlaUser 的别名

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

Construct a new BackendNode instance wrapping a new DbNode instance.

参数:
  • 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)[源代码]#

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

参数:
  • source – the node from which the link is coming

  • link_type – the link type

  • link_label – the link label

返回:

True if the proposed link is allowed, False otherwise

抛出:
property attributes#

Return the complete attributes dictionary.

警告

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.

返回:

the attributes as a dictionary

attributes_items() Iterable[Tuple[str, Any]][源代码]#

Return an iterator over the attributes.

返回:

an iterator with attribute key value pairs

attributes_keys() Iterable[str][源代码]#

Return an iterator over the attribute keys.

返回:

an iterator with attribute keys

clean_values()[源代码]#

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()[源代码]#

Delete all attributes.

clone()[源代码]#

Return an unstored clone of ourselves.

返回:

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

property computer#

Return the computer of this node.

返回:

the computer or None

property ctime#

Return the node ctime.

返回:

the ctime

delete_attribute(key: str) None[源代码]#

Delete an attribute.

参数:

key – name of the attribute

抛出:

AttributeError – if the attribute does not exist

delete_attribute_many(keys: Iterable[str]) None[源代码]#

Delete multiple attributes.

参数:

keys – names of the attributes to delete

抛出:

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

property description#

Return the node description.

返回:

the description

get_attribute(key: str) Any[源代码]#

Return the value of an attribute.

警告

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.

参数:

key – name of the attribute

返回:

the value of the attribute

抛出:

AttributeError – if the attribute does not exist

property label#

Return the node label.

返回:

the label

property mtime#

Return the node mtime.

返回:

the mtime

property node_type#

Return the node type.

返回:

the node type

property process_type#

Return the node process type.

返回:

the process type

property repository_metadata#

Return the node repository metadata.

返回:

the repository metadata

reset_attributes(attributes: Dict[str, Any]) None[源代码]#

Reset the attributes.

备注

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

参数:

attributes – a dictionary with the attributes to set

set_attribute(key: str, value: Any) None[源代码]#

Set an attribute to the given value.

参数:
  • key – name of the attribute

  • value – value of the attribute

set_attribute_many(attributes: Dict[str, Any]) None[源代码]#

Set multiple attributes.

备注

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

参数:

attributes – a dictionary with the attributes to set

store(links=None, clean=True)[源代码]#

Store this entity

返回:

the entity itself

property user#

Return the user of this node.

返回:

the user

property uuid#

Return the node UUID.

返回:

the string representation of the UUID

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

基类:BackendNodeCollection

The collection of Node entries.

ENTITY_CLASS#

SqlaNode 的别名

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

Remove a Node entry from the collection with the given id

参数:

pk – id of the node to delete

get(pk)[源代码]#

Return a Node entry from the collection with the given id

参数:

pk – id of the node

SQLA user

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

基类:SqlaModelEntity[DbUser], BackendUser

SQLA user

MODEL_CLASS#

DbUser 的别名

__abstractmethods__ = frozenset({})#
__init__(backend, email, first_name, last_name, institution)[源代码]#
__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

返回:

the email address

property first_name#

Get the user’s first name

返回:

the first name

property institution#

Get the user’s institution

返回:

the institution

property last_name#

Get the user’s last name

返回:

the last name

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

基类:BackendUserCollection

Collection of SQLA Users

ENTITY_CLASS#

SqlaUser 的别名

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

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)[源代码]#

基类: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)[源代码]#

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.

参数:

item – the name of the model field

返回:

the value of the model’s attribute

__init__(model, backend: PsqlDosBackend)[源代码]#

Construct the ModelWrapper.

参数:
  • model – the ORM model instance to wrap

  • backend – the storage backend instance

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

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.

参数:
  • 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)[源代码]#

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

参数:

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

_flush(fields=())[源代码]#

Flush the fields of the model to the database.

备注

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

参数:

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

_in_transaction()[源代码]#

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

返回:

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

_is_model_field(field)[源代码]#

Return whether the field is a field of the model.

返回:

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

_is_mutable_model_field(field)[源代码]#

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

返回:

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

is_saved()[源代码]#

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

返回:

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

save()[源代码]#

Store the model instance.

备注

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

抛出:

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)[源代码]#

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

参数:

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