trw.reporting.table_sqlite

Module Contents

Classes

TableStream

A SQLite table that can be streamed.

Functions

table_create(cursor, table_name, name_type_list, primary_key)

Create a table

table_insert(cursor, table_name, names, values)

Insert into an existing table

table_drop(cursor, table_name)

Delete a table

table_truncate(cursor, table_name)

Clear all the rows of a table

get_table_number_of_rows(cursor, table_name)

Return the number of rows of a table

get_tables_name_and_role(cursor)

Return all the table names and table role

get_table_data(cursor, table_name, single_row=False, replace_none=False)

Extract all the data of the table

get_data_types_and_clean_data(data)

Remove the type columns (e.g., BLOB_NUMPY, BLOB_IMAGE_PNG) from the data and return

get_metadata_name(table_name)

Return the name of the table metadata for table table_name

table_add_columns(cursor, table_name, column_names)

Attributes

SQLITE_TYPE_PATTERN

logger

trw.reporting.table_sqlite.SQLITE_TYPE_PATTERN = _type
trw.reporting.table_sqlite.logger
trw.reporting.table_sqlite.table_create(cursor, table_name, name_type_list, primary_key)

Create a table

Parameters
  • cursor – the cursor

  • table_name – the name of the table

  • name_type_list – a list of tuple (name, type)

  • primary_key – feature index of the primary key or None

trw.reporting.table_sqlite.table_insert(cursor, table_name, names, values)

Insert into an existing table

Parameters
  • cursor – the cursor

  • table_name – the name of the table

  • names – the names of the columns to insert

  • values – the values of the columns to insert

trw.reporting.table_sqlite.table_drop(cursor, table_name)

Delete a table

Returns

True if table was removed, False else

trw.reporting.table_sqlite.table_truncate(cursor, table_name)

Clear all the rows of a table

Returns

True if table was removed, False else

trw.reporting.table_sqlite.get_table_number_of_rows(cursor, table_name)

Return the number of rows of a table

trw.reporting.table_sqlite.get_tables_name_and_role(cursor)

Return all the table names and table role

Parameters

cursor – the DB cursor

Returns

a list of (table name, table role)

trw.reporting.table_sqlite.get_table_data(cursor, table_name, single_row=False, replace_none=False)

Extract all the data of the table

Parameters
  • cursor – the DB cursor

  • table_name – the name of the database

  • single_row – if True, returns a single row

  • replace_none – if True, replace all None values by empty string

Returns

a dictionary of (name, values)

trw.reporting.table_sqlite.get_data_types_and_clean_data(data)

Remove the type columns (e.g., BLOB_NUMPY, BLOB_IMAGE_PNG) from the data and return column types.

Parameters

data – a dictionary of (name, values)

Returns

a dictionary of (name, type) for names that have specified type

trw.reporting.table_sqlite.get_metadata_name(table_name)

Return the name of the table metadata for table table_name

trw.reporting.table_sqlite.table_add_columns(cursor, table_name, column_names)
class trw.reporting.table_sqlite.TableStream(cursor, table_name, table_role, primary_key=None, table_preamble='')

A SQLite table that can be streamed.

Two tables will be created:

  1. in table_name:
    • feature name with *_type will have SQLITE type type

  2. in ``table_name``_metadata:
    • table_role: the role of the table

    • table_preamble: an explanation or complementary info of the table

_create(self, table_name, name_type_list, table_role, primary_key=0)
_insert(self, batch)
insert(self, batch)

Insert a batch of data to the table. If the table doesn’t exist, it will be created.

Parameters

batch – a dictionary like of names and values. All values must have the same length.

get_column_names(self)