(P) storage

(M) AlembicEnvBase

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

Bases: object


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]

(M) DbConnection

class peek_plugin_base.storage.DbConnection.DbConnection(dbConnectString: str, metadata: sqlalchemy.sql.schema.MetaData, alembicDir: str, dbEngineArgs: typing.Union[typing.Dict[str, typing.Union[str, int]], NoneType] = 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.

  • 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.


Close All Session

Close all ORM sessions connected to this DB engine.


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]


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


Get Orm Session

Returns:A SQLAlchemy session scoped for the callers thread..
prefetchDeclarativeIds(*args, **kwargs)

(M) StorageUtil

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

Make Core Values Subquery

  • 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: typing.List[typing.Union[int, str]])[source]

Make Orm Values Subquery

  • 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.


alias of LargeBinary