build_tools.corpus_db_viewer.queries

Database query functions for corpus database viewer.

All functions provide read-only access to the SQLite database.

Functions

get_tables_list(db_path)

Get list of all tables in the database.

get_table_schema(db_path, table_name)

Get schema information for a specific table.

get_table_data(db_path, table_name[, page, limit, ...])

Get paginated data from a table.

get_row_count(db_path, table_name)

Get total number of rows in a table.

Module Contents

build_tools.corpus_db_viewer.queries.get_tables_list(db_path)[source]

Get list of all tables in the database.

Parameters

db_pathPath

Path to SQLite database file

Returns

list[dict[str, str]]

List of tables, each with ‘name’ and ‘type’ keys

Examples

>>> tables = get_tables_list(Path("data/raw/syllable_extractor.db"))
>>> for table in tables:
...     print(table['name'])
build_tools.corpus_db_viewer.queries.get_table_schema(db_path, table_name)[source]

Get schema information for a specific table.

Parameters

db_pathPath

Path to SQLite database file

table_namestr

Name of the table to inspect

Returns

dict[str, Any]

Dictionary with keys: - ‘columns’: List of column info dicts (cid, name, type, notnull, dflt_value, pk) - ‘indexes’: List of index info dicts with nested column information - ‘create_sql’: Original CREATE TABLE statement

Examples

>>> schema = get_table_schema(Path("data/raw/syllable_extractor.db"), "runs")
>>> print(schema['columns'])
>>> print(schema['create_sql'])
build_tools.corpus_db_viewer.queries.get_table_data(db_path, table_name, page=1, limit=50, sort_by='', sort_order='ASC')[source]

Get paginated data from a table.

Parameters

db_pathPath

Path to SQLite database file

table_namestr

Name of the table to query

pageint, optional

Page number (1-indexed), by default 1

limitint, optional

Number of rows per page, by default 50

sort_bystr, optional

Column name to sort by, by default “” (no sorting)

sort_orderstr, optional

Sort order “ASC” or “DESC”, by default “ASC”

Returns

dict[str, Any]

Dictionary with keys: - ‘rows’: List of row data as dicts - ‘total’: Total number of rows in table - ‘page’: Current page number - ‘limit’: Rows per page - ‘total_pages’: Total number of pages

Examples

>>> data = get_table_data(
...     Path("data/raw/syllable_extractor.db"),
...     "runs",
...     page=1,
...     limit=10,
...     sort_by="run_timestamp",
...     sort_order="DESC"
... )
>>> print(f"Showing page {data['page']} of {data['total_pages']}")
>>> for row in data['rows']:
...     print(row)
build_tools.corpus_db_viewer.queries.get_row_count(db_path, table_name)[source]

Get total number of rows in a table.

Parameters

db_pathPath

Path to SQLite database file

table_namestr

Name of the table

Returns

int

Number of rows in the table

Examples

>>> count = get_row_count(Path("data/raw/syllable_extractor.db"), "runs")
>>> print(f"Total runs: {count}")