(P) storage

(M) AlembicEnvBase

class peek_plugin_base.storage.AlembicEnvBase.AlembicEnvBase(targetMetadata)[source]

Bases: object

run()[source]

Run migrations in ‘online’ mode.

In this scenario we need to create an Engine and associate a connection with the context.

peek_plugin_base.storage.AlembicEnvBase.ensureSchemaExists(engine, schemaName)[source]
peek_plugin_base.storage.AlembicEnvBase.isMssqlDialect(engine)[source]
peek_plugin_base.storage.AlembicEnvBase.isPostGreSQLDialect(engine)[source]

(M) DbConnection

class peek_plugin_base.storage.DbConnection.DbConnection(dbConnectString: str, metadata: sqlalchemy.sql.schema.MetaData, alembicDir: str, dbEngineArgs: Optional[Dict[str, Union[str, int]]] = None, enableForeignKeys=False, enableCreateAll=True)[source]

Bases: object

SQLAlchemy Database Connection

This class takes care of migrating the database and establishing thing database connections and ORM sessions.

Parameters:
  • dbConnectString – The connection string for the DB. See http://docs.sqlalchemy.org/en/latest/core/engines.html
  • metadata – The instance of the metadata for this connection, This is schema qualified MetaData(schema=”schama_name”)
  • alembicDir – The absolute location of the alembic directory (versions dir lives under this)
  • dbEngineArgs – The arguments to pass to the database engine, See http://docs.sqlalchemy.org/en/latest/core/engines.html#engine-creation-api
  • enableCreateAll – If the schema doesn’t exist, then the migration is allowed to use matadata.create_all()
  • enableForeignKeys – Perform a check to ensure foriegn keys have indexes after the db is migrated and connected.
checkForeignKeys(engine: sqlalchemy.engine.base.Engine) → None[source]

Check Foreign Keys

Log any foreign keys that don’t have indexes assigned to them. This is a performance issue.

closeAllSessions()[source]

Close All Session

Close all ORM sessions connected to this DB engine.

dbEngine

Get DB Engine

This is not thread safe, use the ormSesson to execute SQL statements instead. self.ormSession.execute(…)

Returns:the DB Engine used to connect to the database.
migrate() → None[source]

Migrate

Perform a database migration, upgrading to the latest schema level.

ormSessionCreator

Get Orm Session

Returns:A SQLAlchemy session scoped for the callers thread..
prefetchDeclarativeIds(**kwargs)
peek_plugin_base.storage.DbConnection.convertToCoreSqlaInsert(ormObj, Declarative)[source]
peek_plugin_base.storage.DbConnection.pgCopyInsert(rawConn, table, inserts)[source]

(M) StorageUtil

peek_plugin_base.storage.StorageUtil.makeCoreValuesSubqueryCondition(engine, column, values: List[Union[int, str]])[source]

Make Core Values Subquery

Parameters:
  • engine – The database engine, used to determine the dialect
  • column – The column, eg TableItem.__table__.c.colName
  • values – A list of string or int values
peek_plugin_base.storage.StorageUtil.makeOrmValuesSubqueryCondition(ormSession, column, values: List[Union[int, str]])[source]

Make Orm Values Subquery

Parameters:
  • ormSession – The orm session instance
  • column – The column from the Declarative table, eg TableItem.colName
  • values – A list of string or int values

(M) TypeDecorators

class peek_plugin_base.storage.TypeDecorators.PeekLargeBinary(*args, **kwargs)[source]

Bases: sqlalchemy.sql.type_api.TypeDecorator

Construct a TypeDecorator.

Arguments sent here are passed to the constructor of the class assigned to the impl class level attribute, assuming the impl is a callable, and the resulting object is assigned to the self.impl instance attribute (thus overriding the class attribute of the same name).

If the class level impl is not a callable (the unusual case), it will be assigned to the same instance attribute ‘as-is’, ignoring those arguments passed to the constructor.

Subclasses can override this to customize the generation of self.impl entirely.

bind_expression(bindvalue)[source]

“Given a bind value (i.e. a BindParameter instance), return a SQL expression in its place.

This is typically a SQL function that wraps the existing bound parameter within the statement. It is used for special data types that require literals being wrapped in some special database function in order to coerce an application-level value into a database-specific format. It is the SQL analogue of the TypeEngine.bind_processor() method.

The method is evaluated at statement compile time, as opposed to statement construction time.

Note that this method, when implemented, should always return the exact same structure, without any conditional logic, as it may be used in an executemany() call against an arbitrary number of bound parameter sets.

See also

types_sql_value_processing

impl

alias of sqlalchemy.sql.sqltypes.LargeBinary