aiida.backends.djsite.querybuilder_django package¶
Submodules¶
The dummy model encodes the model defined by django in backends.djsite using SQLAlchemy. This is done to query the database with more performant ORM of SA.
-
class
aiida.backends.djsite.querybuilder_django.dummy_model.
DbAttribute
(**kwargs)[source]¶ Bases:
sqlalchemy.ext.declarative.api.Base
-
__init__
(**kwargs)¶ A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs
.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
-
__mapper__
= <Mapper at 0x7f20c7c33350; DbAttribute>¶
-
__module__
= 'aiida.backends.djsite.querybuilder_django.dummy_model'¶
-
__table__
= Table('db_dbattribute', MetaData(bind=None), Column('id', Integer(), table=<db_dbattribute>, primary_key=True, nullable=False), Column('dbnode_id', Integer(), ForeignKey('db_dbnode.id'), table=<db_dbattribute>), Column('key', String(length=255), table=<db_dbattribute>), Column('datatype', String(length=10), table=<db_dbattribute>), Column('tval', String(), table=<db_dbattribute>, default=ColumnDefault('')), Column('fval', Float(), table=<db_dbattribute>), Column('ival', Integer(), table=<db_dbattribute>), Column('bval', Boolean(), table=<db_dbattribute>), Column('dval', DateTime(), table=<db_dbattribute>), schema=None)¶
-
__tablename__
= 'db_dbattribute'¶
-
_sa_class_manager
= {'bval': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'datatype': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'dbnode_id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'dval': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'fval': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'ival': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'key': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'tval': <sqlalchemy.orm.attributes.InstrumentedAttribute object>}¶
-
bval
¶
-
datatype
¶
-
dbnode_id
¶
-
dval
¶
-
fval
¶
-
id
¶
-
ival
¶
-
key
¶
-
tval
¶
-
-
class
aiida.backends.djsite.querybuilder_django.dummy_model.
DbCalcState
(**kwargs)[source]¶ Bases:
sqlalchemy.ext.declarative.api.Base
-
__init__
(**kwargs)¶ A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs
.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
-
__mapper__
= <Mapper at 0x7f20c7b48450; DbCalcState>¶
-
__module__
= 'aiida.backends.djsite.querybuilder_django.dummy_model'¶
-
__table__
= Table('db_dbcalcstate', MetaData(bind=None), Column('id', Integer(), table=<db_dbcalcstate>, primary_key=True, nullable=False), Column('state', String(length=255), table=<db_dbcalcstate>), Column('time', DateTime(timezone=True), table=<db_dbcalcstate>, default=ColumnDefault(<function <lambda>>)), Column('dbnode_id', Integer(), ForeignKey('db_dbnode.id'), table=<db_dbcalcstate>), schema=None)¶
-
__table_args__
= (UniqueConstraint(Column('dbnode_id', Integer(), ForeignKey('db_dbnode.id'), table=<db_dbcalcstate>), Column('state', String(length=255), table=<db_dbcalcstate>)),)¶
-
__tablename__
= 'db_dbcalcstate'¶
-
_sa_class_manager
= {'dbnode': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'dbnode_id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'state': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'time': <sqlalchemy.orm.attributes.InstrumentedAttribute object>}¶
-
dbnode
¶
-
dbnode_id
¶
-
id
¶
-
state
¶
-
time
¶
-
-
class
aiida.backends.djsite.querybuilder_django.dummy_model.
DbComputer
(**kwargs)[source]¶ Bases:
sqlalchemy.ext.declarative.api.Base
-
__init__
(**kwargs)¶ A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs
.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
-
__mapper__
= <Mapper at 0x7f20c7b654d0; DbComputer>¶
-
__module__
= 'aiida.backends.djsite.querybuilder_django.dummy_model'¶
-
__table__
= Table('db_dbcomputer', MetaData(bind=None), Column('id', Integer(), table=<db_dbcomputer>, primary_key=True, nullable=False), Column('uuid', UUID(as_uuid=True), table=<db_dbcomputer>, default=ColumnDefault(<function <lambda>>)), Column('name', String(length=255), table=<db_dbcomputer>, nullable=False), Column('hostname', String(length=255), table=<db_dbcomputer>), Column('description', Text(), table=<db_dbcomputer>), Column('enabled', Boolean(), table=<db_dbcomputer>), Column('transport_type', String(length=255), table=<db_dbcomputer>), Column('scheduler_type', String(length=255), table=<db_dbcomputer>), Column('transport_params', String(length=255), table=<db_dbcomputer>), Column('metadata', String(length=255), table=<db_dbcomputer>, default=ColumnDefault('{}')), schema=None)¶
-
__tablename__
= 'db_dbcomputer'¶
-
_metadata
¶
-
_sa_class_manager
= {'_metadata': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'description': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'enabled': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'hostname': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'name': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'scheduler_type': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'transport_params': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'transport_type': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'uuid': <sqlalchemy.orm.attributes.InstrumentedAttribute object>}¶
-
description
¶
-
enabled
¶
-
hostname
¶
-
id
¶
-
name
¶
-
scheduler_type
¶
-
transport_params
¶
-
transport_type
¶
-
uuid
¶
-
-
class
aiida.backends.djsite.querybuilder_django.dummy_model.
DbExtra
(**kwargs)[source]¶ Bases:
sqlalchemy.ext.declarative.api.Base
-
__init__
(**kwargs)¶ A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs
.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
-
__mapper__
= <Mapper at 0x7f20c7ce9f90; DbExtra>¶
-
__module__
= 'aiida.backends.djsite.querybuilder_django.dummy_model'¶
-
__table__
= Table('db_dbextra', MetaData(bind=None), Column('id', Integer(), table=<db_dbextra>, primary_key=True, nullable=False), Column('dbnode_id', Integer(), ForeignKey('db_dbnode.id'), table=<db_dbextra>), Column('key', String(length=255), table=<db_dbextra>), Column('datatype', String(length=10), table=<db_dbextra>), Column('tval', String(), table=<db_dbextra>, default=ColumnDefault('')), Column('fval', Float(), table=<db_dbextra>), Column('ival', Integer(), table=<db_dbextra>), Column('bval', Boolean(), table=<db_dbextra>), Column('dval', DateTime(), table=<db_dbextra>), schema=None)¶
-
__tablename__
= 'db_dbextra'¶
-
_sa_class_manager
= {'bval': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'datatype': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'dbnode_id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'dval': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'fval': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'ival': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'key': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'tval': <sqlalchemy.orm.attributes.InstrumentedAttribute object>}¶
-
bval
¶
-
datatype
¶
-
dbnode_id
¶
-
dval
¶
-
fval
¶
-
id
¶
-
ival
¶
-
key
¶
-
tval
¶
-
-
class
aiida.backends.djsite.querybuilder_django.dummy_model.
DbGroup
(**kwargs)[source]¶ Bases:
sqlalchemy.ext.declarative.api.Base
-
__init__
(**kwargs)¶ A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs
.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
-
__mapper__
= <Mapper at 0x7f20c7b753d0; DbGroup>¶
-
__module__
= 'aiida.backends.djsite.querybuilder_django.dummy_model'¶
-
__table__
= Table('db_dbgroup', MetaData(bind=None), Column('id', Integer(), table=<db_dbgroup>, primary_key=True, nullable=False), Column('uuid', UUID(as_uuid=True), table=<db_dbgroup>, default=ColumnDefault(<function <lambda>>)), Column('name', String(length=255), table=<db_dbgroup>), Column('type', String(length=255), table=<db_dbgroup>, default=ColumnDefault('')), Column('time', DateTime(timezone=True), table=<db_dbgroup>, default=ColumnDefault(<function <lambda>>)), Column('description', Text(), table=<db_dbgroup>), Column('user_id', Integer(), ForeignKey('db_dbuser.id'), table=<db_dbgroup>), schema=None)¶
-
__table_args__
= (UniqueConstraint(Column('name', String(length=255), table=<db_dbgroup>), Column('type', String(length=255), table=<db_dbgroup>, default=ColumnDefault(''))),)¶
-
__tablename__
= 'db_dbgroup'¶
-
_sa_class_manager
= {'dbnodes': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'description': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'name': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'time': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'type': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'user': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'user_id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'uuid': <sqlalchemy.orm.attributes.InstrumentedAttribute object>}¶
-
dbnodes
¶
-
description
¶
-
id
¶
-
name
¶
-
time
¶
-
type
¶
-
user
¶
-
user_id
¶
-
uuid
¶
-
-
class
aiida.backends.djsite.querybuilder_django.dummy_model.
DbLink
(**kwargs)[source]¶ Bases:
sqlalchemy.ext.declarative.api.Base
-
__init__
(**kwargs)¶ A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs
.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
-
__mapper__
= <Mapper at 0x7f20c7bf2c10; DbLink>¶
-
__module__
= 'aiida.backends.djsite.querybuilder_django.dummy_model'¶
-
__table__
= Table('db_dblink', MetaData(bind=None), Column('id', Integer(), table=<db_dblink>, primary_key=True, nullable=False), Column('input_id', Integer(), ForeignKey('db_dbnode.id'), table=<db_dblink>), Column('output_id', Integer(), ForeignKey('db_dbnode.id'), table=<db_dblink>), Column('type', String(length=255), table=<db_dblink>), Column('label', String(length=255), table=<db_dblink>, nullable=False), schema=None)¶
-
__tablename__
= 'db_dblink'¶
-
_sa_class_manager
= {'id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'input': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'input_id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'label': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'output': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'output_id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'type': <sqlalchemy.orm.attributes.InstrumentedAttribute object>}¶
-
id
¶
-
input
¶
-
input_id
¶
-
label
¶
-
output
¶
-
output_id
¶
-
type
¶
-
-
class
aiida.backends.djsite.querybuilder_django.dummy_model.
DbNode
(**kwargs)[source]¶ Bases:
sqlalchemy.ext.declarative.api.Base
-
__init__
(**kwargs)¶ A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs
.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
-
__mapper__
= <Mapper at 0x7f20c7b8a3d0; DbNode>¶
-
__module__
= 'aiida.backends.djsite.querybuilder_django.dummy_model'¶
-
__table__
= Table('db_dbnode', MetaData(bind=None), Column('id', Integer(), table=<db_dbnode>, primary_key=True, nullable=False), Column('uuid', UUID(as_uuid=True), table=<db_dbnode>, default=ColumnDefault(<function <lambda>>)), Column('type', String(length=255), table=<db_dbnode>), Column('label', String(length=255), table=<db_dbnode>), Column('description', Text(), table=<db_dbnode>), Column('ctime', DateTime(timezone=True), table=<db_dbnode>, default=ColumnDefault(<function <lambda>>)), Column('mtime', DateTime(timezone=True), table=<db_dbnode>, default=ColumnDefault(<function <lambda>>)), Column('dbcomputer_id', Integer(), ForeignKey('db_dbcomputer.id'), table=<db_dbnode>), Column('user_id', Integer(), ForeignKey('db_dbuser.id'), table=<db_dbnode>, nullable=False), Column('public', Boolean(), table=<db_dbnode>, default=ColumnDefault(False)), Column('nodeversion', Integer(), table=<db_dbnode>, default=ColumnDefault(1)), schema=None)¶
-
__tablename__
= 'db_dbnode'¶
-
_sa_class_manager
= {'attributes': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'ctime': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'dbcomputer': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'dbcomputer_id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'description': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'extras': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'label': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'mtime': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'nodeversion': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'outputs': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'public': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'type': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'user': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'user_id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'uuid': <sqlalchemy.orm.attributes.InstrumentedAttribute object>}¶
-
attributes
¶
-
computer_name
= <sqlalchemy.sql.elements.Label object>¶
-
ctime
¶
-
dbcomputer
¶
-
dbcomputer_id
¶
-
description
¶
-
extras
¶
-
get_aiida_class
()[source]¶ Return the corresponding instance of
Node()
or a subclass return by the plugin loader.Todo
The behavior is quite pathetic, creating a django DbNode instance to instantiate the aiida instance. These means that every time you load Aiida instances with the QueryBuilder when using Django as a backend, three instances are instantiated for every Aiida instance you load! Could be fixed by allowing DbNode from the dummy nodel to be passed to AiidaNode’s __init__.
Returns: An instance of the plugin class
-
id
¶
-
label
¶
-
mtime
¶
-
nodeversion
¶
-
outputs
¶
-
public
¶
-
state
= <sqlalchemy.sql.elements.Label object>¶
-
type
¶
-
user
¶
-
user_email
= <sqlalchemy.sql.elements.Label object>¶
-
user_id
¶
-
uuid
¶
-
-
class
aiida.backends.djsite.querybuilder_django.dummy_model.
DbUser
(**kwargs)[source]¶ Bases:
sqlalchemy.ext.declarative.api.Base
-
__init__
(**kwargs)¶ A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs
.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
-
__mapper__
= <Mapper at 0x7f20c7b6e150; DbUser>¶
-
__module__
= 'aiida.backends.djsite.querybuilder_django.dummy_model'¶
-
__table__
= Table('db_dbuser', MetaData(bind=None), Column('id', Integer(), table=<db_dbuser>, primary_key=True, nullable=False), Column('email', String(length=254), table=<db_dbuser>), Column('password', String(length=128), table=<db_dbuser>), Column('first_name', String(length=254), table=<db_dbuser>), Column('last_name', String(length=254), table=<db_dbuser>), Column('institution', String(length=254), table=<db_dbuser>), Column('is_staff', Boolean(), table=<db_dbuser>, default=ColumnDefault(False)), Column('is_active', Boolean(), table=<db_dbuser>, default=ColumnDefault(False)), Column('last_login', DateTime(timezone=True), table=<db_dbuser>, default=ColumnDefault(<function <lambda>>)), Column('date_joined', DateTime(timezone=True), table=<db_dbuser>, default=ColumnDefault(<function <lambda>>)), schema=None)¶
-
__tablename__
= 'db_dbuser'¶
-
_sa_class_manager
= {'date_joined': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'email': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'first_name': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'id': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'institution': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'is_active': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'is_staff': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'last_login': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'last_name': <sqlalchemy.orm.attributes.InstrumentedAttribute object>, 'password': <sqlalchemy.orm.attributes.InstrumentedAttribute object>}¶
-
date_joined
¶
-
email
¶
-
first_name
¶
-
id
¶
-
institution
¶
-
is_active
¶
-
is_staff
¶
-
last_login
¶
-
last_name
¶
-
password
¶
-
-
aiida.backends.djsite.querybuilder_django.dummy_model.
get_aldjemy_session
()[source]¶ Use aldjemy to make a session
-
class
aiida.backends.djsite.querybuilder_django.querybuilder_django.
QueryBuilderImplDjango
(*args, **kwargs)[source]¶ Bases:
aiida.backends.general.querybuilder_interface.QueryBuilderInterface
-
AiidaComputer
¶
-
AiidaGroup
¶
-
AiidaNode
¶
-
AiidaUser
¶
-
Computer
¶
-
Group
¶
-
Link
¶
-
Node
¶
-
User
¶
-
__abstractmethods__
= frozenset([])¶
-
__module__
= 'aiida.backends.djsite.querybuilder_django.querybuilder_django'¶
-
_abc_cache
= <_weakrefset.WeakSet object>¶
-
_abc_negative_cache
= <_weakrefset.WeakSet object>¶
-
_abc_negative_cache_version
= 40¶
-
_abc_registry
= <_weakrefset.WeakSet object>¶
-
first
(query)[source]¶ Executes query in the backend asking for one instance.
Returns: One row of aiida results
-
get_aiida_res
(key, res)[source]¶ Some instance returned by ORM (django or SA) need to be converted to Aiida instances (eg nodes)
Parameters: - res – the result returned by the query
- key – the key that this entry would be return with
Returns: an aiida-compatible instance
-
get_filter_expr
(operator, value, attr_key, is_attribute, alias=None, column=None, column_name=None)[source]¶ 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:
Parameters: - 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]
- for floats and integers:
- >
- <
- <=
- >=
- for strings:
- 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’)
- for arrays only (SQLAlchemy version):
- 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
(operator, value, attr_key, column=None, column_name=None, alias=None)[source]¶ A classmethod that returns an valid SQLAlchemy expression.
Parameters: - 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.
Returns: An instance of sqlalchemy.sql.elements.BinaryExpression
-
iterall
(query, batch_size, tag_to_index_dict)[source]¶ Returns: An iterator over all the results of a list of lists.
-
iterdict
(query, batch_size, tag_to_projected_entity_dict)[source]¶ Returns: An iterator over all the results of a list of dictionaries.
-
modify_expansions
(alias, expansions)[source]¶ For the Django schema, we have as additioanl expansions ‘attributes’ and ‘extras’
-
table_groups_nodes
¶
-