database
create_schema(db_connection, new_schema, logger)
¶
CREATE SCHEMA IF NOT EXISTS new_schema
Source code in packages/common/src/bag3d/common/utils/database.py
118 119 120 121 122 123 | |
drop_table(db_connection, new_table, logger)
¶
DROP TABLE IF EXISTS new_table CASCADE
Source code in packages/common/src/bag3d/common/utils/database.py
110 111 112 113 114 115 | |
load_sql(filename=None, query_params=None)
¶
Load SQL from a file and inject parameters if provided.
If providing query parametes, they need to be in a dict, where the keys are the parameter names.
The SQL script can contain parameters in the form of ${...}, which is
understood by most database managers. This is handy for developing the SQL scripts
in a database manager, without having to execute the pipeline.
However, the python formatting only understands {...} placeholders, so the
$ are removed from ${...} when the SQL is loaded from the file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
SQL File to load (without the path) from the |
None
|
query_params
|
dict
|
If provided, the templated SQL is formatted with the parameters. |
None
|
For example:
.. code-block:: python
def my_func():
load_sql() # loads my_func.sql from bag3d_pipeline.sql
Source code in packages/common/src/bag3d/common/utils/database.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
table_exists(db_connection, table)
¶
CHECKS IF TABLE EXISTS
Source code in packages/common/src/bag3d/common/utils/database.py
126 127 128 129 130 131 132 133 134 135 136 137 138 | |