flexget.utils.sqlalchemy_utils module#

Miscellaneous SQLAlchemy helpers.

class flexget.utils.sqlalchemy_utils.ContextSession(bind=None, *, autoflush=True, future=True, expire_on_commit=True, autobegin=True, twophase=False, binds=None, enable_baked_queries=True, info=None, query_cls=None, autocommit=False, join_transaction_mode='conditional_savepoint', close_resets_only=_NoArg.NO_ARG)[source]#

Bases: Session

sqlalchemy.orm.Session which automatically commits when used as context manager without errors.

Parameters:
  • bind (Optional[_SessionBind])

  • autoflush (bool)

  • future (Literal[True])

  • expire_on_commit (bool)

  • autobegin (bool)

  • twophase (bool)

  • binds (Optional[Dict[_SessionBindKey, _SessionBind]])

  • enable_baked_queries (bool)

  • info (Optional[_InfoType])

  • query_cls (Optional[Type[Query[Any]]])

  • autocommit (Literal[False])

  • join_transaction_mode (JoinTransactionMode)

  • close_resets_only (Union[bool, _NoArg])

flexget.utils.sqlalchemy_utils.create_index(table_name, session, *column_names)[source]#

Create an index on specified columns in table_name.

Parameters:
  • table_name (str) – Name of table to create the index on.

  • session (Session) – Session object which should be used

  • column_names (str) – The names of the columns that should belong to this index.

Return type:

None

flexget.utils.sqlalchemy_utils.drop_index(table_name, index_name, session)[source]#

Drop an index by table name and index name.

Parameters:
  • table_name (string) – Name of table

  • index_name (string) – Name of the index

  • session (Session) – SQLAlchemy Session

Return type:

None

flexget.utils.sqlalchemy_utils.drop_tables(names, session)[source]#

Take a list of table names and drops them from the database if they exist.

Parameters:
Return type:

None

flexget.utils.sqlalchemy_utils.get_index_by_name(table, name)[source]#

Find declaratively defined index from table by name.

Parameters:
  • table (Table) – Table object

  • name (string) – Name of the index to get

Returns:

Index object

Return type:

Index | None

flexget.utils.sqlalchemy_utils.index_exists(table_name, index_name, session)[source]#

Use SQLAlchemy reflect to check index existences.

Parameters:
  • table_name (string) – Table name to check

  • index_name (string) – Index name to check

  • session (Session) – Session to use

Returns:

True if table exists, False otherwise

Return type:

bool

flexget.utils.sqlalchemy_utils.table_add_column(table, name, col_type, session, default=None)[source]#

Add a column to a table.

Warning

Uses raw statements, probably needs to be changed in order to work on other databases besides SQLite

Parameters:
  • table (string) – Table to add column to (can be name or schema)

  • name (string) – Name of new column to add

  • col_type (TypeEngine | type) – The sqlalchemy column type to add

  • session (Session) – SQLAlchemy Session to do the alteration

  • default (Any) – Default value for the created column (optional)

Return type:

None

flexget.utils.sqlalchemy_utils.table_columns(table, session)[source]#

Return list of column names in the table or empty list.

Parameters:
  • table (string) – Name of table or table schema

  • session (Session) – SQLAlchemy Session

Return type:

list[str]

flexget.utils.sqlalchemy_utils.table_exists(name, session)[source]#

Use SQLAlchemy reflect to check table existences.

Parameters:
  • name (string) – Table name to check

  • session (Session) – Session to use

Returns:

True if table exists, False otherwise

Return type:

bool

flexget.utils.sqlalchemy_utils.table_index(table_name, index_name, session)[source]#

Find an index by table name and index name.

Parameters:
  • table_name (string) – Name of table

  • index_name (string) – Name of the index

  • session (Session) – SQLAlchemy Session

Returns:

The requested index

Return type:

Index

flexget.utils.sqlalchemy_utils.table_schema(name, session)[source]#

Return Table schema using SQLAlchemy reflect as it currently exists in the db.

Parameters:
Return type:

Table