common_sqlite
SQLite utility functions that are independent of API version.
DatabaseError
Bases: Exception
General LUTE database error.
Source code in lute/io/_db/common_sqlite.py
12 13 14 15 | |
compare_cols(cols1, cols2)
Compare whether two sets of columns are identical.
The comparison is unidirectional - This function tests for columns present
in cols2 which are not present in cols1, but NOT vice versa. Switch the
order of the arguments in order to retrieve the other comparison.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cols1
|
Dict[str, str]
|
Dictionary of first set of column names and types. |
required |
cols2
|
Dict[str, str]
|
Dictionary of second set of column names and types. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
diff |
Dict[str, str] | None
|
Any columns present in |
Source code in lute/io/_db/common_sqlite.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
does_table_exist(con, table_name)
Check whether a table exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
con
|
Connection
|
Database connection. |
required |
table_name
|
str
|
The table to check for. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
does_exist |
bool
|
Whether the table exists. |
Source code in lute/io/_db/common_sqlite.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
get_all_rows_for_table(con, table_name)
Return all rows for a requested table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
con
|
Connection
|
Database connection. |
required |
table_name
|
str
|
The table's name. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
rows |
List[Tuple[Any, ...]]
|
ALL rows for a table. |
Source code in lute/io/_db/common_sqlite.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
get_table_cols(con, table_name)
Retrieve the columns currently present in a table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
con
|
Connection
|
Database connection. |
required |
table_name
|
str
|
The table's name. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
cols |
Dict[str, str]
|
A dictionary of column names and types. |
Source code in lute/io/_db/common_sqlite.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
get_tables(con)
Retrieve a list of all tables in a database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
con
|
Connection
|
Database connection. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tables |
List[str]
|
A list of database tables. |
Source code in lute/io/_db/common_sqlite.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |