aiida.orm.implementation.sql package

This module is for subclasses of the generic backend entities that only apply to SQL backends

All SQL backends with an ORM should subclass from the classes in this module

class aiida.orm.implementation.sql.SqlBackend[source]

Bases: typing.Generic, aiida.orm.implementation.backends.Backend

A class for SQL based backends. Assumptions are that:
  • there is an ORM

  • that it is possible to convert from ORM model instances to backend instances

  • that psycopg2 is used as the engine

if any of these assumptions do not fit then just implement a backend from aiida.orm.implementation.Backend

__abstractmethods__ = frozenset({'authinfos', 'comments', 'computers', 'cursor', 'execute_raw', 'get_backend_entity', 'groups', 'logs', 'migrate', 'nodes', 'query', 'query_manager', 'transaction', 'users'})
__dict__ = mappingproxy({'__module__': 'aiida.orm.implementation.sql.backends', '__doc__': '\n A class for SQL based backends. Assumptions are that:\n * there is an ORM\n * that it is possible to convert from ORM model instances to backend instances\n * that psycopg2 is used as the engine\n\n if any of these assumptions do not fit then just implement a backend from :class:`aiida.orm.implementation.Backend`\n ', 'get_backend_entity': <function SqlBackend.get_backend_entity>, 'cursor': <function SqlBackend.cursor>, 'execute_raw': <function SqlBackend.execute_raw>, 'execute_prepared_statement': <function SqlBackend.execute_prepared_statement>, '__orig_bases__': (typing.Generic[~ModelType], <class 'aiida.orm.implementation.backends.Backend'>), '__dict__': <attribute '__dict__' of 'SqlBackend' objects>, '__weakref__': <attribute '__weakref__' of 'SqlBackend' objects>, '__parameters__': (~ModelType,), '__abstractmethods__': frozenset({'query', 'migrate', 'authinfos', 'logs', 'execute_raw', 'query_manager', 'get_backend_entity', 'comments', 'users', 'nodes', 'cursor', 'computers', 'transaction', 'groups'}), '_abc_impl': <_abc_data object>})
__module__ = 'aiida.orm.implementation.sql.backends'
__orig_bases__ = (typing.Generic[~ModelType], <class 'aiida.orm.implementation.backends.Backend'>)
__parameters__ = (~ModelType,)
__weakref__

list of weak references to the object (if defined)

_abc_impl = <_abc_data object>
abstract cursor()[source]

Return a psycopg cursor. This method should be used as a context manager i.e.:

with backend.cursor():
    # Do stuff
Returns

a psycopg cursor

Return type

psycopg2.extensions.cursor

execute_prepared_statement(sql, parameters)[source]

Execute an SQL statement with optional prepared statements.

Parameters
  • sql – the SQL statement string

  • parameters – dictionary to use to populate the prepared statement

abstract execute_raw(query)[source]

Execute a raw SQL statement and return the result.

Parameters

query – a string containing a raw SQL statement

Returns

the result of the query

abstract get_backend_entity(model)[source]

Return the backend entity that corresponds to the given Model instance

Parameters

model – the ORM model instance to promote to a backend instance

Returns

the backend entity corresponding to the given model

Return type

aiida.orm.implementation.BackendEntity

Submodules

Generic backend related objects

class aiida.orm.implementation.sql.backends.SqlBackend[source]

Bases: typing.Generic, aiida.orm.implementation.backends.Backend

A class for SQL based backends. Assumptions are that:
  • there is an ORM

  • that it is possible to convert from ORM model instances to backend instances

  • that psycopg2 is used as the engine

if any of these assumptions do not fit then just implement a backend from aiida.orm.implementation.Backend

__abstractmethods__ = frozenset({'authinfos', 'comments', 'computers', 'cursor', 'execute_raw', 'get_backend_entity', 'groups', 'logs', 'migrate', 'nodes', 'query', 'query_manager', 'transaction', 'users'})
__dict__ = mappingproxy({'__module__': 'aiida.orm.implementation.sql.backends', '__doc__': '\n A class for SQL based backends. Assumptions are that:\n * there is an ORM\n * that it is possible to convert from ORM model instances to backend instances\n * that psycopg2 is used as the engine\n\n if any of these assumptions do not fit then just implement a backend from :class:`aiida.orm.implementation.Backend`\n ', 'get_backend_entity': <function SqlBackend.get_backend_entity>, 'cursor': <function SqlBackend.cursor>, 'execute_raw': <function SqlBackend.execute_raw>, 'execute_prepared_statement': <function SqlBackend.execute_prepared_statement>, '__orig_bases__': (typing.Generic[~ModelType], <class 'aiida.orm.implementation.backends.Backend'>), '__dict__': <attribute '__dict__' of 'SqlBackend' objects>, '__weakref__': <attribute '__weakref__' of 'SqlBackend' objects>, '__parameters__': (~ModelType,), '__abstractmethods__': frozenset({'query', 'migrate', 'authinfos', 'logs', 'execute_raw', 'query_manager', 'get_backend_entity', 'comments', 'users', 'nodes', 'cursor', 'computers', 'transaction', 'groups'}), '_abc_impl': <_abc_data object>})
__module__ = 'aiida.orm.implementation.sql.backends'
__orig_bases__ = (typing.Generic[~ModelType], <class 'aiida.orm.implementation.backends.Backend'>)
__parameters__ = (~ModelType,)
__weakref__

list of weak references to the object (if defined)

_abc_impl = <_abc_data object>
abstract cursor()[source]

Return a psycopg cursor. This method should be used as a context manager i.e.:

with backend.cursor():
    # Do stuff
Returns

a psycopg cursor

Return type

psycopg2.extensions.cursor

execute_prepared_statement(sql, parameters)[source]

Execute an SQL statement with optional prepared statements.

Parameters
  • sql – the SQL statement string

  • parameters – dictionary to use to populate the prepared statement

abstract execute_raw(query)[source]

Execute a raw SQL statement and return the result.

Parameters

query – a string containing a raw SQL statement

Returns

the result of the query

abstract get_backend_entity(model)[source]

Return the backend entity that corresponds to the given Model instance

Parameters

model – the ORM model instance to promote to a backend instance

Returns

the backend entity corresponding to the given model

Return type

aiida.orm.implementation.BackendEntity