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:
Sessionsqlalchemy.orm.Sessionwhich 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.
- 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.
- flexget.utils.sqlalchemy_utils.get_index_by_name(table, name)[source]#
Find declaratively defined index from table by name.
- flexget.utils.sqlalchemy_utils.index_exists(table_name, index_name, session)[source]#
Use SQLAlchemy reflect to check index existences.
- 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.
- flexget.utils.sqlalchemy_utils.table_exists(name, session)[source]#
Use SQLAlchemy reflect to check table existences.