database
create_schema(context, new_schema)
¶
CREATE SCHEMA IF NOT EXISTS new_schema
Source code in packages/common/src/bag3d/common/utils/database.py
111 112 113 114 115 116 | |
drop_table(context, new_table)
¶
DROP TABLE IF EXISTS new_table CASCADE
Source code in packages/common/src/bag3d/common/utils/database.py
103 104 105 106 107 108 | |
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
9 10 11 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 | |
table_exists(context, table)
¶
CHECKS IF TABLE EXISTS
Source code in packages/common/src/bag3d/common/utils/database.py
119 120 121 122 123 124 125 126 127 128 129 | |