trw.reporting.table_sqlite
¶
Module Contents¶
Classes¶
A SQLite table that can be streamed. |
Functions¶
|
Create a table |
|
Insert into an existing table |
|
Delete a table |
|
Clear all the rows of a table |
|
Return the number of rows of a table |
|
Return all the table names and table role |
|
Extract all the data of the table |
Remove the type columns (e.g., BLOB_NUMPY, BLOB_IMAGE_PNG) from the data and return |
|
|
Return the name of the table metadata for table |
|
Attributes¶
- 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:
- in
table_name
: feature name with
*_type
will have SQLITE typetype
- in
- in ``table_name``_metadata:
table_role
: the role of the tabletable_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)¶