app.utilities.databases package

Submodules

app.utilities.databases.sct_db module

sct_db.py

This module initiates SCT Tool RDBMS operations

app.utilities.databases.sct_db.init_app_database(app)

Initiate application databased for SCT tool

Parameters:

app – Flask application object

Returns:

None

app.utilities.databases.sct_db.init_audit_database(app)

Initiate application databased for SCT tool

Parameters:

app – Flask application object

Returns:

None

app.utilities.databases.sct_mysql module

sct_db.py

This module controls SCT Tool specific database interaction

class app.utilities.databases.sct_mysql.DbBackEnd(database: str = 'default', schema=None, user: str = 'mysql', password: str = 'mysql', host: str = 'localhost', port: str = '3306')

Bases: object

Backend Database Interface. .. admonition:: Note

Defines all DB Communication codes.

add_audit(audit_table: str, status: str, audit_user: str, operation_performed: str, table_name: str, operation_metadata: str)

Insert a Audit record

Parameters:
  • audit_table – Audit table name

  • status – Audit operation status

  • audit_user – Audit user

  • operation_performed – Audit operation

  • table_name – Table impacted

  • operation_metadata – Operation detail

Returns:

None

add_table_record(table: str, **kwargs)

Add row to table

Parameters:
  • table – Table name

  • kwargs – List of column values of new record

Returns:

None

bulk_load_table_records(table: str, file_path: str)

Add row to table

Parameters:
  • table – Table name

  • file_path – File name to load table from

Returns:

None

create_audit_table(audit_table: str)

Create a Audit table

Parameters:

audit_table – Audit table name

Returns:

None

property db_connection

DB Connection

Returns:

Postgres DB API Connection

drop_table_record(table: str, **kwargs)

Drop row from table

Parameters:
  • table – Table name

  • kwargs – List of column values of new record

Returns:

None

edit_table_record(table: str, **kwargs)

Edit row to table

Parameters:
  • table – Table name

  • kwargs – List of column values of new record

Returns:

None

finalize(e=None)

Closes a DbBackEnd

Returns:

None

get_audits(audit_table: str, batch: int = 1, page_size: int = 3) dict

Get Audits

Parameters:
  • audit_table – Audit table name

  • batch – Row batch, where each batch will be of size 50 at least

  • page_size – Max record per page

Returns:

Audit data

property get_cursor

DB Cursor

Returns:

Postgres DB API Cursor from connection

get_pending_bulk_loading(audit_table, max_failure)

List of files pending for processing

Parameters:
  • audit_table – Audit table name

  • max_failure – Max number of failure before we discard a file

Returns:

dictionary with keys for table name and file to load

get_table_columns(table: str, load_fk_data: bool = False) dict

Column list for a table

Parameters:
  • table – Table name

  • load_fk_data – Whether to load FK column data for lookup

Returns:

Metadata dictionary

get_table_data(table: str, project_list: list, order_list: list, limit: int, offset: int = 0)

Fetch data for a table

Parameters:
  • table – Table name

  • project_list – List of columns to project

  • order_list – List of columns to order data by

  • limit – Max rows fetched

  • offset – Row batch, where each batch will be of size 50 at least

Returns:

List of rows

get_table_info(table: str, batch: int = 1, page_size: int = 3) dict

Table metadata

Parameters:
  • table – Table name

  • batch – Row batch, where each batch will be of size 50 at least

  • page_size – Max record per page

Returns:

Metadata dictionary

get_table_list(blk_listed_table: str = '', schema: str = 'public') list

Return list of table name in DB

Parameters:
  • blk_listed_table – Black Listed Table

  • schema – DB Schema

Returns:

List of Tables

search_audits(audit_table: str, audit_search_col: str, audit_search_op: str, audit_search_val: str, batch: int = 1, page_size: int = 3) dict

Search Audits

Parameters:
  • audit_table – Audit table name

  • audit_search_col – Audit table search column name

  • audit_search_op – Audit table search operator

  • audit_search_val – Audit table search value

  • batch – Row batch, where each batch will be of size 50 at least

  • page_size – Max record per page

Returns:

Audit data

search_table_data(table: str, project_list: list, order_list: list, search_con, limit: int, offset: int = 0)

Search data for a table

Parameters:
  • table – Table name

  • project_list – List of columns to project

  • order_list – List of columns to order data by

  • search_con – Searched Condition

  • limit – Max rows fetched

  • offset – Row batch, where each batch will be of size 50 at least

Returns:

List of rows

search_table_info(table: str, search_col, search_op, search_val, batch: int = 1, page_size: int = 3) dict

Search metadata

Parameters:
  • table – Table name

  • search_col – Searched Table Column

  • search_op – Search Operation

  • search_val – Search Value

  • batch – Row batch, where each batch will be of size 50 at least

  • page_size – Max record per page

Returns:

Metadata dictionary

app.utilities.databases.sct_mysql_query module

sct_mysql_query.py

This module consists of MySQL Queries

app.utilities.databases.sct_postgres module

sct_db.py

This module controls SCT Tool specific database interaction

class app.utilities.databases.sct_postgres.DbBackEnd(database: str = 'default', schema=None, user: str = 'postgres', password: str = 'postgres', host: str = 'localhost', port: str = '5432')

Bases: object

Backend Database Interface. .. admonition:: Note

Defines all DB Communication codes.

add_audit(audit_table: str, status: str, audit_user: str, operation_performed: str, table_name: str, operation_metadata: str)

Insert a Audit record

Parameters:
  • audit_table – Audit table name

  • status – Audit operation status

  • audit_user – Audit user

  • operation_performed – Audit operation

  • table_name – Table impacted

  • operation_metadata – Operation detail

Returns:

None

add_table_record(table: str, **kwargs)

Add row to table

Parameters:
  • table – Table name

  • kwargs – List of column values of new record

Returns:

None

bulk_load_table_records(table: str, file_path: str)

Add row to table

Parameters:
  • table – Table name

  • file_path – File name to load table from

Returns:

None

create_audit_table(audit_table: str)

Create a Audit table

Parameters:

audit_table – Audit table name

Returns:

None

property db_connection

DB Connection

Returns:

Postgres DB API Connection

drop_table_record(table: str, **kwargs)

Drop row from table

Parameters:
  • table – Table name

  • kwargs – List of column values of new record

Returns:

None

edit_table_record(table: str, **kwargs)

Edit row to table

Parameters:
  • table – Table name

  • kwargs – List of column values of new record

Returns:

None

finalize(e=None)

Closes a DbBackEnd

Returns:

None

get_audits(audit_table: str, batch: int = 1, page_size: int = 3) dict

Get Audits

Parameters:
  • audit_table – Audit table name

  • batch – Row batch, where each batch will be of size 50 at least

  • page_size – Max record per page

Returns:

Audit data

property get_cursor

DB Cursor

Returns:

Postgres DB API Cursor from connection

get_pending_bulk_loading(audit_table, max_failure)

List of files pending for processing

Parameters:
  • audit_table – Audit table name

  • max_failure – Max number of failure before we discard a file

Returns:

dictionary with keys for table name and file to load

get_table_columns(table: str, load_fk_data: bool = False) dict

Column list for a table

Parameters:
  • table – Table name

  • load_fk_data – Whether to load FK column data for lookup

Returns:

Metadata dictionary

get_table_data(table: str, project_list: list, order_list: list, limit: int, offset: int = 0)

Fetch data for a table

Parameters:
  • table – Table name

  • project_list – List of columns to project

  • order_list – List of columns to order data by

  • limit – Max rows fetched

  • offset – Row batch, where each batch will be of size 50 at least

Returns:

List of rows

get_table_info(table: str, batch: int = 1, page_size: int = 3) dict

Table metadata

Parameters:
  • table – Table name

  • batch – Row batch, where each batch will be of size 50 at least

  • page_size – Max record per page

Returns:

Metadata dictionary

get_table_list(blk_listed_table: str = '', schema: str = 'public') list

Return list of table name in DB

Parameters:
  • blk_listed_table – Black Listed Table

  • schema – DB Schema

Returns:

List of Tables

search_audits(audit_table: str, audit_search_col: str, audit_search_op: str, audit_search_val: str, batch: int = 1, page_size: int = 3) dict

Search Audits

Parameters:
  • audit_table – Audit table name

  • audit_search_col – Audit table search column name

  • audit_search_op – Audit table search operator

  • audit_search_val – Audit table search value

  • batch – Row batch, where each batch will be of size 50 at least

  • page_size – Max record per page

Returns:

Audit data

search_table_data(table: str, project_list: list, order_list: list, search_con, limit: int, offset: int = 0)

Search data for a table

Parameters:
  • table – Table name

  • project_list – List of columns to project

  • order_list – List of columns to order data by

  • search_con – Searched Condition

  • limit – Max rows fetched

  • offset – Row batch, where each batch will be of size 50 at least

Returns:

List of rows

search_table_info(table: str, search_col, search_op, search_val, batch: int = 1, page_size: int = 3) dict

Search metadata

Parameters:
  • table – Table name

  • search_col – Searched Table Column

  • search_op – Search Operation

  • search_val – Search Value

  • batch – Row batch, where each batch will be of size 50 at least

  • page_size – Max record per page

Returns:

Metadata dictionary

app.utilities.databases.sct_postgres_query module

sct_query.py

This module consists of RDBMS Queries

app.utilities.databases.sct_sqlite module

sct_sqlite.py

This module controls SCT Tool specific SQLite database interaction

class app.utilities.databases.sct_sqlite.DbBackEnd(database: str = ':memory:', schema=None, user: str = '', password: str = '', host: str = '', port: str = '')

Bases: object

Backend SQLite Database Interface. .. admonition:: Note

Defines all DB Communication codes.

add_audit(audit_table: str, status: str, audit_user: str, operation_performed: str, table_name: str, operation_metadata: dict)

Insert a Audit record

Parameters:
  • audit_table – Audit table name

  • status – Audit operation status

  • audit_user – Audit user

  • operation_performed – Audit operation

  • table_name – Table impacted

  • operation_metadata – Operation detail

Returns:

None

add_table_record(table: str, **kwargs)

Add row to table

Parameters:
  • table – Table name

  • kwargs – List of column values of new record

Returns:

None

bulk_load_table_records(table: str, file_path: str)

Add row to table

Parameters:
  • table – Table name

  • file_path – File name to load table from

Returns:

None

create_audit_table(audit_table: str)

Create a Audit table

Parameters:

audit_table – Audit table name

Returns:

None

property db_connection

DB Connection

Returns:

Postgres DB API Connection

drop_table_record(table: str, **kwargs)

Drop row from table

Parameters:
  • table – Table name

  • kwargs – List of column values of new record

Returns:

None

edit_table_record(table: str, **kwargs)

Edit row to table

Parameters:
  • table – Table name

  • kwargs – List of column values of new record

Returns:

None

finalize(e=None)

Closes a DbBackEnd

Returns:

None

get_audits(audit_table: str, batch: int = 1, page_size: int = 3) dict

Get Audits

Parameters:
  • audit_table – Audit table name

  • batch – Row batch, where each batch will be of size 50 at least

  • page_size – Max record per page

Returns:

Audit data

property get_cursor

DB Cursor

Returns:

Postgres DB API Cursor from connection

get_pending_bulk_loading(audit_table, max_failure)

List of files pending for processing

Parameters:
  • audit_table – Audit table name

  • max_failure – Max number of failure before we discard a file

Returns:

dictionary with keys for table name and file to load

get_table_columns(table: str, load_fk_data: bool = False) dict

Column list for a table

Parameters:
  • table – Table name

  • load_fk_data – Whether to load FK column data for lookup

Returns:

Metadata dictionary

get_table_data(table: str, project_list: list, order_list: list, limit: int, offset: int = 0)

Fetch data for a table

Parameters:
  • table – Table name

  • project_list – List of columns to project

  • order_list – List of columns to order data by

  • limit – Max rows fetched

  • offset – Row batch, where each batch will be of size 50 at least

Returns:

List of rows

get_table_info(table: str, batch: int = 1, page_size: int = 3) dict

Table metadata

Parameters:
  • table – Table name

  • batch – Row batch, where each batch will be of size 50 at least

  • page_size – Max record per page

Returns:

Metadata dictionary

get_table_list(blk_listed_table: str = '', schema: str | None = None) list

Return list of table name in DB

Parameters:
  • blk_listed_table – Black Listed Table

  • schema – DB Schema

Returns:

List of Tables

search_audits(audit_table: str, audit_search_col: str, audit_search_op: str, audit_search_val: str, batch: int = 1, page_size: int = 3) dict

Search Audits

Parameters:
  • audit_table – Audit table name

  • audit_search_col – Audit table search column name

  • audit_search_op – Audit table search operator

  • audit_search_val – Audit table search value

  • batch – Row batch, where each batch will be of size 50 at least

  • page_size – Max record per page

Returns:

Audit data

search_table_data(table: str, project_list: list, order_list: list, search_con, limit: int, offset: int = 0)

Search data for a table

Parameters:
  • table – Table name

  • project_list – List of columns to project

  • order_list – List of columns to order data by

  • search_con – Searched Condition

  • limit – Max rows fetched

  • offset – Row batch, where each batch will be of size 50 at least

Returns:

List of rows

search_table_info(table: str, search_col, search_op, search_val, batch: int = 1, page_size: int = 3) dict

Search metadata

Parameters:
  • table – Table name

  • search_col – Searched Table Column

  • search_op – Search Operation

  • search_val – Search Value

  • batch – Row batch, where each batch will be of size 50 at least

  • page_size – Max record per page

Returns:

Metadata dictionary

app.utilities.databases.sct_sqlite_query module

sct_sqlite_query.py

This module consists of SQLite Queries

Module contents