SQLite Database¶
SQLiteDatabase
¶
SQLite database management and DataFrame persistence.
Purpose
Provides Data Management table operations, DataFrame transformations, interactive visualizations, and SQLite persistence.
Attributes:
| Name | Type | Description |
|---|---|---|
db_path |
str
|
Current SQLite database file path from configuration. |
table |
str
|
Current table used by a database utility operation. |
table_name |
str
|
Current table name for DataFrame persistence. |
column |
str
|
Current column for database schema operations. |
col_type |
str
|
Column type for schema updates. |
limit |
Optional[int]
|
Maximum number of rows in the latest table read. |
offset |
int
|
Starting row offset in the latest table read. |
df_input |
Optional[DataFrame]
|
Input DataFrame for persistence operations. |
Initialize the configured SQLite database path.
Purpose
Initialize the configured SQLite database path.
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Completes the operation through side effects. |
Source code in storage.py
Methods:¶
validate_database_file
¶
Validate the required pre-hydrated SQLite database.
Purpose
Reject missing, invalid, or unhydrated Git LFS files before opening SQLite.
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
Validated absolute SQLite database path. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
When the database file is missing. |
ValueError
|
When the file does not have a SQLite header. |
Source code in storage.py
create_connection
¶
Connect to an existing database for explicit Data Management writes.
Purpose
Preserve intentional writes but reject a missing pre-hydrated database.
Returns:
| Type | Description |
|---|---|
Connection
|
sqlite3.Connection: Read-write connection to the existing database. |
Source code in storage.py
create_read_connection
¶
Connect to the operational SQLite database without write privileges.
Purpose
Use read-only connections for map queries and metadata inspection.
Returns:
| Type | Description |
|---|---|
Connection
|
sqlite3.Connection: Read-only connection to the existing database. |
Source code in storage.py
list_tables
¶
List the tables present in the configured SQLite database.
Purpose
List the tables present in the configured SQLite database.
Returns:
| Type | Description |
|---|---|
List[str]
|
List[ str ]: Result of the list tables operation. |
Source code in storage.py
create_schema
¶
Read the column metadata of a SQLite table.
Purpose
Read the column metadata of a SQLite table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
str
|
SQLite table name. |
required |
Returns:
| Type | Description |
|---|---|
List[Tuple]
|
List[ Tuple ]: Result of the create schema operation. |
Source code in storage.py
read_selected_columns
¶
Load only the requested columns of an existing SQLite table.
Purpose
Support schema-aware interactive mapping without loading unrelated large text and binary fields. Validate identifiers against live SQLite metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
str
|
Existing SQLite table name. |
required |
columns
|
List[str]
|
Nonempty column list drawn from the table schema. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Selected database records in their original column order. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When required arguments are missing or unknown identifiers occur. |
TypeError
|
When argument types are invalid. |
Error
|
When database retrieval fails. |
Source code in storage.py
1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 | |
read_table
¶
Read a SQLite table into a pandas DataFrame using a normalized scalar-only path.
Purpose
Read a SQLite table into a pandas DataFrame using a normalized scalar-only path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
str
|
Table name. |
required |
limit
|
Optional[int]
|
Maximum rows to retrieve; None selects all rows. |
None
|
offset
|
int
|
Number of rows to skip, starting at zero. |
0
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: DataFrame of plain Python scalar values. |
Source code in storage.py
1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 | |
render_table
¶
Render a DataFrame safely in Streamlit. Use the normal interactive dataframe.
Purpose
Render a DataFrame safely in Streamlit. Use the normal interactive dataframe first, and fall back to HTML rendering if Streamlit/PyArrow serialization fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The DataFrame to render. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Renders the selected database table in Streamlit. |
Source code in storage.py
make_display_safe
¶
Return a DataFrame with values suitable for Streamlit rendering.
Purpose
Return a DataFrame with values suitable for Streamlit rendering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input pandas DataFrame. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Result of the make display safe operation. |
Source code in storage.py
drop_table
¶
Safely drop a table if it exists.
Purpose
Safely drop a table if it exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
str
|
Table name. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Completes the operation through side effects. |
Source code in storage.py
create_index
¶
Create a safe SQLite index on a specified table column.
Purpose
Create a safe SQLite index on a specified table column.
Handles: - Spaces in column names - Special characters - Reserved words - Duplicate index names - Validation against actual table schema
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
str
|
Table name. |
required |
column
|
str
|
Column name to index. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Completes the operation through side effects. |
Source code in storage.py
apply_filters
¶
Render advanced DataFrame filters and return the filtered rows.
Purpose
Render advanced DataFrame filters and return the filtered rows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input pandas DataFrame. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Result of the apply filters operation. |
Source code in storage.py
create_aggregation
¶
Calculate and display a selected numeric aggregation.
Purpose
Calculate and display a selected numeric aggregation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input pandas DataFrame. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Displays the selected aggregation result in Streamlit, or an informational message when no numeric column exists. |
Source code in storage.py
create_visualization
¶
Render data visualizations without passing pandas objects directly into.
Purpose
Render data visualizations without passing pandas objects directly into Plotly/Narwhals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The input DataFrame. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Renders a visualization in the Streamlit interface. |
Source code in storage.py
1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 | |
convert_dataframe
¶
Create a SQLite table from the DataFrame's column types.
Purpose
Create a SQLite table from the DataFrame's column types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table_name
|
str
|
SQLite table name. |
required |
df
|
DataFrame
|
Input pandas DataFrame. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Creates a SQLite table using the input DataFrame's inferred column types. |
Source code in storage.py
insert_data
¶
Insert a DataFrame's rows into a SQLite table.
Purpose
Insert a DataFrame's rows into a SQLite table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table_name
|
str
|
SQLite table name. |
required |
df
|
DataFrame
|
Input pandas DataFrame. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Inserts the DataFrame rows into the selected SQLite table. |
Source code in storage.py
get_sqlite_type
¶
Map a pandas dtype to an appropriate SQLite column type.
Purpose
Map a pandas dtype to an appropriate SQLite column type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dtype
|
pandas dtype
|
The dtype of a pandas Series. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
SQLite column type. |
Source code in storage.py
create_custom_table
¶
Create a custom SQLite table from column definitions.
Purpose
Create a custom SQLite table from column definitions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table_name
|
str
|
Name of table. |
required |
columns
|
list of dict
|
[ { "name": str, "type": str, "not_null": bool, "primary_key": bool, "auto_increment": bool } ] |
required |
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Completes the operation through side effects. |
Source code in storage.py
is_safe_query
¶
Determine whether a SQL query is read-only and safe to execute.
Purpose
Determine whether a SQL query is read-only and safe to execute.
Allows: SELECT WITH (CTE returning SELECT) EXPLAIN SELECT PRAGMA (read-only)
Blocks: INSERT, UPDATE, DELETE, DROP, ALTER, CREATE, ATTACH, DETACH, VACUUM, REPLACE, TRIGGER, and multiple statements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
SQL query or identifier to inspect. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
Result of the is safe query operation. |
Source code in storage.py
1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 | |
create_identifier
¶
Sanitize a string into a safe SQLite identifier.
Purpose
Sanitize a string into a safe SQLite identifier.
- Replaces invalid characters with underscores
- Ensures it starts with a letter or underscore
- Prevents empty names
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Original identifier to sanitize. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Result of the create identifier operation. |
Source code in storage.py
get_indexes
¶
Return index metadata for a SQLite table.
Purpose
Return index metadata for a SQLite table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
str
|
SQLite table name. |
required |
Returns:
| Type | Description |
|---|---|
List[Tuple]
|
List[Tuple]: SQLite index metadata rows returned by PRAGMA index_list. |
Source code in storage.py
add_column
¶
Add a typed column to an existing SQLite table.
Purpose
Add a typed column to an existing SQLite table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
str
|
SQLite table name. |
required |
column
|
str
|
SQLite column name. |
required |
col_type
|
str
|
SQLite column type. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Adds the specified column to the existing SQLite table. |
Source code in storage.py
rename_column
¶
Rename a column within an existing SQLite table. Attempts native ALTER TABLE rename.
Purpose
Rename a column within an existing SQLite table. Attempts native ALTER TABLE rename first; if it fails, falls back to a schema-safe rebuild preserving column order, data, and indexes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table_name
|
str
|
Table containing the column. |
required |
old_name
|
str
|
Existing column name. |
required |
new_name
|
str
|
New column name. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Renames the selected SQLite column. |
Source code in storage.py
1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 | |
create_profile_table
¶
Build column-level descriptive statistics for a table.
Purpose
Build column-level descriptive statistics for a table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
str
|
SQLite table name. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Per-column statistics including null counts, distinct counts, and numeric summaries. |
Source code in storage.py
drop_column
¶
Remove a column while rebuilding the table and restoring indexes.
Purpose
Remove a column while rebuilding the table and restoring indexes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
str
|
SQLite table name. |
required |
column
|
str
|
SQLite column name. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Rebuilds the table without the selected column and restores indexes. |
Source code in storage.py
1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 | |
rename_table
¶
Rename an existing SQLite table. Attempts native ALTER TABLE rename first; if it fails,.
Purpose
Rename an existing SQLite table. Attempts native ALTER TABLE rename first; if it fails, falls back to a schema-safe rebuild using the original CREATE TABLE statement and preserves indexes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
old_name
|
str
|
Existing table name. |
required |
new_name
|
str
|
New table name. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
Renames the selected SQLite table. |
Source code in storage.py
2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 | |