_sqlite
Backend SQLite database utilites.
Functions should be used only by the higher-level database module.
_add_row_no_duplicate(con, table_name, entry)
Add a new row to a table with no duplicates.
This function will check first to see if the entry exists in the table. If there is already a row with the provided information, its ID is returned. Otherwise a new row is added and the ID of the newly inserted row is returned.
The tables for general configuration and Executor configuration assume that there are no duplicates as information is intended to be shared and linked to by multiple Tasks.
This function ASSUMES the table EXISTS. Perform creation and necessary existence checks before using it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
con
|
Connection
|
Database connection. |
required |
table_name
|
str
|
The table to add a new row with |
required |
entry
|
Dict[str, Any]
|
A dictionary of entries in the format of {COLUMN: ENTRY}. These are assumed to match the columns of the table. |
required |
Returns:
Name | Type | Description |
---|---|---|
row_id |
int
|
The row id of the newly added entry or the last entry which matches the provided values. |
Source code in lute/io/_sqlite.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
|
_add_task_entry(con, task_name, entry)
Add an entry to a task table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
con
|
Connection
|
Database connection. |
required |
task_name
|
str
|
The Task's name. This will be provided by the Task. In most cases this is the Python class' name. |
required |
entry
|
Dict[str, Any]
|
A dictionary of entries in the format of {COLUMN: ENTRY}. These are assumed to match the columns of the table. |
required |
Source code in lute/io/_sqlite.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
|
_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/_sqlite.py
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 128 129 130 |
|
_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/_sqlite.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
|
_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/_sqlite.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
|
_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/_sqlite.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
_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/_sqlite.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
|
_make_shared_table(con, table_name, columns)
Create a general configuration table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
con
|
Connection
|
Database connection. |
required |
table_name
|
str
|
Name of the table to create. |
required |
columns
|
Dict[str, str]
|
A dictionary of columns in the format of {COLNAME:TYPE}. |
required |
Source code in lute/io/_sqlite.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
|
_make_task_table(con, task_name, columns)
Create a sqlite Task table for LUTE's specification.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
con
|
Connection
|
Database connection. |
required |
task_name
|
str
|
The Task's name. This will be provided by the Task. In most cases this is the Python class' name. |
required |
columns
|
Dict[str, str]
|
A dictionary of columns in the format of {COLNAME:TYPE}. These match the parameters of the Task and the Result fields of the Task. Additional more general columns are appended within this function. Other helper functions can be used for generating the dictionary from a TaskParameters object. |
required |
Returns:
Name | Type | Description |
---|---|---|
success |
bool
|
Whether the table was created correctly or not. |
Source code in lute/io/_sqlite.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|