Module for the SqlAlchemy backend implementation of the AuthInfo ORM class.
aiida.orm.implementation.sqlalchemy.authinfos.
SqlaAuthInfo
Bases: aiida.orm.implementation.sqlalchemy.entities.SqlaModelEntity, aiida.orm.implementation.authinfos.BackendAuthInfo
aiida.orm.implementation.sqlalchemy.entities.SqlaModelEntity
aiida.orm.implementation.authinfos.BackendAuthInfo
SqlAlchemy backend implementation for the AuthInfo ORM class.
MODEL_CLASS
alias of aiida.backends.sqlalchemy.models.authinfo.DbAuthInfo
aiida.backends.sqlalchemy.models.authinfo.DbAuthInfo
__abstractmethods__
__init__
Construct a new instance.
computer – a aiida.orm.implementation.computers.BackendComputer instance
aiida.orm.implementation.computers.BackendComputer
user – a aiida.orm.implementation.users.BackendUser instance
aiida.orm.implementation.users.BackendUser
an aiida.orm.implementation.authinfos.BackendAuthInfo instance
__module__
__orig_bases__
__parameters__
_abc_impl
computer
Return the computer associated with this instance.
enabled
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
id
Get the id of this entity
the entity id
is_stored
Return whether the entity is stored.
True if stored, False otherwise
bool
set_auth_params
Set the dictionary of authentication parameters
auth_params – a dictionary with authentication parameters
set_metadata
Set the dictionary of metadata
metadata – a dictionary with metadata
user
Return the user associated with this instance.
SqlaAuthInfoCollection
Bases: aiida.orm.implementation.authinfos.BackendAuthInfoCollection
aiida.orm.implementation.authinfos.BackendAuthInfoCollection
The collection of SqlAlchemy backend AuthInfo entries.
ENTITY_CLASS
alias of SqlaAuthInfo
delete
Delete an entry from the collection.
pk – the pk of the entry to delete
get
Return an entry from the collection that is configured for the given computer and user
aiida.common.exceptions.NotExistent – if no entry exists for the computer/user pair
aiida.common.exceptions.MultipleObjectsError – if multiple entries exist for the computer/user pair
SqlAlchemy implementation of aiida.orm.implementation.backends.Backend.
aiida.orm.implementation.sqlalchemy.backend.
SqlaBackend
Bases: aiida.orm.implementation.sql.backends.SqlBackend
aiida.orm.implementation.sql.backends.SqlBackend
Construct the backend instance by initializing all the collections.
authinfos
Return the collection of authorisation information objects
the authinfo collection
aiida.orm.implementation.BackendAuthInfoCollection
comments
Return the collection of comments
the comment collection
aiida.orm.implementation.BackendCommentCollection
computers
Return the collection of computers
the computers collection
aiida.orm.implementation.BackendComputerCollection
cursor
Return a psycopg cursor to be used in a context manager.
a psycopg cursor
psycopg2.extensions.cursor
execute_raw
Execute a raw SQL statement and return the result.
query – a string containing a raw SQL statement
the result of the query
get_backend_entity
Return a BackendEntity instance from a DbModel instance.
get_connection
Get the SQLA database connection
the SQLA database connection
get_session
Return a database session that can be used by the QueryBuilder to perform its query.
an instance of sqlalchemy.orm.session.Session
sqlalchemy.orm.session.Session
groups
Return the collection of groups
the groups collection
aiida.orm.implementation.BackendGroupCollection
logs
Return the collection of logs
the log collection
aiida.orm.implementation.BackendLogCollection
migrate
Migrate the database to the latest schema generation or version.
nodes
Return the collection of nodes
the nodes collection
aiida.orm.implementation.BackendNodeCollection
query
Return an instance of a query builder implementation for this backend
a new query builder instance
aiida.orm.implementation.BackendQueryBuilder
query_manager
Return the query manager for the objects stored in the backend
The query manger
aiida.backends.general.abstractqueries.AbstractQueryManager
transaction
Open a transaction to be used as a context manager.
If there is an exception within the context then the changes will be rolled back and the state will be as before entering. Transactions can be nested.
users
Return the collection of users
the users collection
aiida.orm.implementation.BackendUserCollection
SQLA implementations for the Comment entity and collection.
aiida.orm.implementation.sqlalchemy.comments.
SqlaComment
Bases: aiida.orm.implementation.sqlalchemy.entities.SqlaModelEntity, aiida.orm.implementation.comments.BackendComment
aiida.orm.implementation.comments.BackendComment
Comment implementation for Sqla.
alias of aiida.backends.sqlalchemy.models.comment.DbComment
aiida.backends.sqlalchemy.models.comment.DbComment
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
a Comment object associated to the given node and user
content
ctime
mtime
node
set_content
set_mtime
set_user
store
Can only store if both the node and user are stored as well.
SqlaCommentCollection
Bases: aiida.orm.implementation.comments.BackendCommentCollection
aiida.orm.implementation.comments.BackendCommentCollection
SqlAlchemy implementation for the CommentCollection.
alias of SqlaComment
create
Create a Comment for a given node and user
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
comment_id
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
Delete Comments based on filters
filters
filters (dict) – similar to QueryBuilder filter
(former) PK s of deleted Comments
PK
list
TypeError – if filters is not a dict
ValidationError – if filters is empty
SqlAlchemy implementations for the Computer entity and collection.
aiida.orm.implementation.sqlalchemy.computers.
SqlaComputer
Bases: aiida.orm.implementation.sqlalchemy.entities.SqlaModelEntity, aiida.orm.implementation.computers.BackendComputer
SqlAlchemy implementation for BackendComputer.
alias of aiida.backends.sqlalchemy.models.computer.DbComputer
aiida.backends.sqlalchemy.models.computer.DbComputer
Initialize self. See help(type(self)) for accurate signature.
copy
Create an unstored clone of an already stored Computer.
description
get_description
get_hostname
Get this computer hostname :rtype: str
get_name
get_scheduler_type
get_transport_type
hostname
Is this entity stored?
name
pk
Return the id for this entity.
This is unique only amongst entities of this type for a particular backend.
set_description
set_hostname
Set the hostname of this computer :param val: The new hostname :type val: str
Set the metadata.
set_name
set_scheduler_type
set_transport_type
Store the Computer instance.
uuid
SqlaComputerCollection
Bases: aiida.orm.implementation.computers.BackendComputerCollection
aiida.orm.implementation.computers.BackendComputerCollection
Collection of Computer instances.
alias of SqlaComputer
Delete an entry with the given pk
list_names
Module to get the backend instance from the Models instance
aiida.orm.implementation.sqlalchemy.convert.
Default get_backend_entity
Classes and methods for Django specific backend entities
aiida.orm.implementation.sqlalchemy.entities.
SqlaModelEntity
Bases: typing.Generic
typing.Generic
A mixin that adds some common SQLA backend entity methods
__dict__
__weakref__
list of weak references to the object (if defined)
_class_check
Assert that the class is correctly configured
_dbmodel
dbmodel
Get the underlying database model instance
the database model instance
from_dbmodel
Create a DjangoEntity from the corresponding db model class
dbmodel – the model to create the entity from
backend – the corresponding backend
the Django entity
get_dbmodel_attribute_name
Given the name of an attribute of the entity class give the corresponding name of the attribute in the db model. It if doesn’t exit this raises a ValueError
attr_name –
the dbmodel attribute name
str
Store this entity
the entity itself
SQLA groups
aiida.orm.implementation.sqlalchemy.groups.
SqlaGroup
Bases: aiida.orm.implementation.sqlalchemy.entities.SqlaModelEntity, aiida.orm.implementation.groups.BackendGroup
aiida.orm.implementation.groups.BackendGroup
The SQLAlchemy Group object
alias of aiida.backends.sqlalchemy.models.group.DbGroup
aiida.backends.sqlalchemy.models.group.DbGroup
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
__int__
Convert the class to an integer. This is needed to allow querying with Django. Be careful, though, not to pass it to a wrong field! This only returns the local DB principal key (pk) value.
the integer pk of the node or None if not stored.
add_nodes
Add a node or a set of nodes to the group.
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
the description of the group as a string
label
the name of the group as a string
Get an iterator to all the nodes in the group
remove_nodes
Remove a node or a set of nodes from the 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.
type_string
the string defining the type of the group
a backend user object, representing the user associated to this group.
aiida.orm.implementation.BackendUser
a string with the uuid
SqlaGroupCollection
Bases: aiida.orm.implementation.groups.BackendGroupCollection
aiida.orm.implementation.groups.BackendGroupCollection
The SLQA collection of groups
alias of SqlaGroup
Delete a group with the given id
id – the id of the group to delete
Query for groups.
By default, query for user-defined groups only (type_string==””). If you want to query for all type of groups, pass type_string=None. If you want to query for a specific type of groups, pass a specific string as the type_string argument.
name – the name of the group
nodes – a node or list of nodes that belongs to the group (alternatively, you can also pass a DbNode or list of DbNodes)
pk – the pk of the group
uuid – the uuid of the group
type_string – the string for the type of node; by default, look only for user-defined groups (see note above).
user – by default, query for groups of all users; if specified, must be a DbUser object, or a string for the user email.
past_days – by default, query for all groups; if specified, query the groups created in the last past_days. Must be a datetime object.
name_filters – dictionary that can contain ‘startswith’, ‘endswith’ or ‘contains’ as keys
node_attributes – if not None, must be a dictionary with format {k: v}. It will filter and return only groups where there is at least a node with an attribute with key=k and value=v. Different keys of the dictionary are joined with AND (that is, the group should satisfy all requirements. v can be a base data type (str, bool, int, float, …) If it is a list or iterable, that the condition is checked so that there should be at least a node in the group with key=k and value=each of the values of the iterable.
kwargs –
any other filter to be passed to DbGroup.objects.filter
node_attributes = {'elements': ['Ba', 'Ti'], 'md5sum': 'xxx'}
it will find groups that contain the node with md5sum = ‘xxx’, and moreover contain at least one node for element ‘Ba’ and one node for element ‘Ti’.
SQLA Log and LogCollection module
aiida.orm.implementation.sqlalchemy.logs.
SqlaLog
Bases: aiida.orm.implementation.sqlalchemy.entities.SqlaModelEntity, aiida.orm.implementation.logs.BackendLog
aiida.orm.implementation.logs.BackendLog
SQLA Log backend entity
alias of aiida.backends.sqlalchemy.models.log.DbLog
aiida.backends.sqlalchemy.models.log.DbLog
dbnode_id
Get the id of the object that created the log entry
levelname
The name of the log level
loggername
The name of the logger that created this entry
message
Get the message corresponding to the entry
metadata
Get the metadata corresponding to the entry
time
Get the time corresponding to the entry
Get the string representation of the UUID of the log entry
SqlaLogCollection
Bases: aiida.orm.implementation.logs.BackendLogCollection
aiida.orm.implementation.logs.BackendLogCollection
The SQLA collection for logs
alias of SqlaLog
Remove a Log entry from the collection with the given id
log_id (int) – id of the Log to delete
TypeError – if log_id is not an int
log_id
NotExistent – if Log with ID log_id is not found
Delete all Log entries.
IntegrityError – if all Logs could not be deleted
Delete Logs based on filters
(former) PK s of deleted Logs
SqlAlchemy implementation of the BackendNode and BackendNodeCollection classes.
aiida.orm.implementation.sqlalchemy.nodes.
SqlaNode
Bases: aiida.orm.implementation.sqlalchemy.entities.SqlaModelEntity, aiida.orm.implementation.nodes.BackendNode
aiida.orm.implementation.nodes.BackendNode
SQLA Node backend entity
alias of aiida.backends.sqlalchemy.models.node.DbNode
aiida.backends.sqlalchemy.models.node.DbNode
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
_add_link
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
add_incoming
True if the proposed link is allowed, False otherwise
aiida.common.ModificationNotAllowed – if either source or target node is not stored
clean_values
clone
Return an unstored clone of ourselves.
an unstored BackendNode with the exact same attributes and extras as self
Return the computer of this node.
the computer or None
BackendComputer or None
Store the node in the database.
links – optional links to add before storing
with_transaction – if False, do not use a transaction because the caller will already have opened one.
clean – boolean, if True, will clean the attributes and extras before attempting to store
Return the user of this node.
the user
BackendUser
SqlaNodeCollection
Bases: aiida.orm.implementation.nodes.BackendNodeCollection
aiida.orm.implementation.nodes.BackendNodeCollection
The collection of Node entries.
alias of SqlaNode
Remove a Node entry from the collection with the given id
pk – id of the node to delete
Return a Node entry from the collection with the given id
pk – id of the node
Sqla query builder implementation
aiida.orm.implementation.sqlalchemy.querybuilder.
SqlaQueryBuilder
Bases: aiida.orm.implementation.querybuilder.BackendQueryBuilder
aiida.orm.implementation.querybuilder.BackendQueryBuilder
QueryBuilder to use with SQLAlchemy-backend and schema defined in backends.sqlalchemy.models
AuthInfo
A property, decorated with @property. Returns the implementation for the AuthInfo
Comment
A property, decorated with @property. Returns the implementation for the Comment
Computer
A property, decorated with @property. Returns the implementation for the Computer
Group
A property, decorated with @property. Returns the implementation for the Group
Link
A property, decorated with @property. Returns the implementation for the DbLink
Log
A property, decorated with @property. Returns the implementation for the Log
Node
Decorated as a property, returns the implementation for DbNode. It needs to return a subclass of sqlalchemy.Base, which means that for different ORM’s a corresponding dummy-model must be written.
User
A property, decorated with @property. Returns the implementation for the User
get_column_names
Given the backend specific alias, return the column names that correspond to the aliased table.
get_filter_expr
Applies a filter on the alias given. Expects the alias of the ORM-class on which to filter, and filter_spec. Filter_spec contains the specification on the filter. Expects:
operator – The operator to apply, see below for further details
value – The value for the right side of the expression, the value you want to compare with.
path – The path leading to the value
attr_key – Boolean, whether the value is in a json-column, or in an attribute like table.
Implemented and valid operators:
for any type: * == (compare single value, eg: ‘==’:5.0) * in (compare whether in list, eg: ‘in’:[5, 6, 34]
>
<
<=
>=
like (case - sensitive), for example ‘like’:’node.calc.%’ will match node.calc.relax and node.calc.RELAX and node.calc. but not node.CALC.relax
ilike (case - unsensitive) will also match node.CaLc.relax in the above example
Note
The character % is a reserved special character in SQL, and acts as a wildcard. If you specifically want to capture a % in the string, use: _%
%
_%
for arrays and dictionaries (only for the SQLAlchemy implementation):
contains: pass a list with all the items that the array should contain, or that should be among the keys, eg: ‘contains’: [‘N’, ‘H’])
has_key: pass an element that the list has to contain or that has to be a key, eg: ‘has_key’:’N’)
of_length
longer
shorter
All the above filters invoke a negation of the expression if preceded by ~:
# first example: filter_spec = { 'name' : { '~in':[ 'halle', 'lujah' ] } # Name not 'halle' or 'lujah' } # second example: filter_spec = { 'id' : { '~==': 2 } } # id is not 2
get_filter_expr_from_attributes
Returns an valid SQLAlchemy expression.
operator – The operator provided by the user (‘==’, ‘>’, …)
value – The value to compare with, e.g. (5.0, ‘foo’, [‘a’,’b’])
attr_key (str) – The path to that attribute as a tuple of values. I.e. if that attribute I want to filter by is the 2nd element in a list stored under the key ‘mylist’, this is (‘mylist’, ‘2’).
column – Optional, an instance of sqlalchemy.orm.attributes.InstrumentedAttribute or
column_name (str) – The name of the column, and the backend should get the InstrumentedAttribute.
alias – The aliased class.
An instance of sqlalchemy.sql.elements.BinaryExpression
get_table_name
Returns the table name given an Aliased class
modify_expansions
In SQLA, the metadata should be changed to _metadata to be in-line with the database schema
table_groups_nodes
A property, decorated with @property. Returns the implementation for the many-to-many relationship between group and nodes.
array_length
Bases: sqlalchemy.sql.functions.FunctionElement
sqlalchemy.sql.functions.FunctionElement
_compiler_dispatcher
compile
Get length of array defined in a JSONB column
jsonb_array_length
jsonb_typeof
SQLA user
aiida.orm.implementation.sqlalchemy.users.
SqlaUser
Bases: aiida.orm.implementation.sqlalchemy.entities.SqlaModelEntity, aiida.orm.implementation.users.BackendUser
alias of aiida.backends.sqlalchemy.models.user.DbUser
aiida.backends.sqlalchemy.models.user.DbUser
email
Get the email address of the user
the email address
first_name
Get the user’s first name
the first name
institution
Get the user’s institution
the institution
last_name
Get the user’s last name
the last name
SqlaUserCollection
Bases: aiida.orm.implementation.users.BackendUserCollection
aiida.orm.implementation.users.BackendUserCollection
Collection of SQLA Users
alias of SqlaUser
Create a user with the provided email address
A new user object
aiida.orm.User
find
Find a user in matching the given criteria
email – the email address
id – the id
the matching user
aiida.orm.implementation.sqlalchemy.users.SqlaUser
Utilities for the implementation of the SqlAlchemy backend.
aiida.orm.implementation.sqlalchemy.utils.
ModelWrapper
Bases: object
object
Wrap a database model instance to correctly update and flush the data model when getting or setting a field.
If the model is not stored, the behavior of the get and set attributes is unaltered. However, if the model is stored, which is to say, it has a primary key, the getattr and setattr are modified as follows:
getattr: if the item corresponds to a mutable model field, the model instance is refreshed first
setattr: if the item corresponds to a mutable model field, changes are flushed after performing the change
__getattr__
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
Construct the ModelWrapper.
model – the database model instance to wrap
auto_flush – an optional tuple of database model fields that are always to be flushed, in addition to the field that corresponds to the attribute being set through __setattr__.
__setattr__
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
_ensure_model_uptodate
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
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
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
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
Retun 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.
disable_expire_on_commit
Context manager that disables expire_on_commit and restores the original value on exit
session (sqlalchemy.orm.session.Session) – The SQLA session