SQL render
get_sql_from_file(filepath, jinja_args=None, **kwargs)
Read in an SQL file and inject arguments with Jinja (if given params). Returns the SQL as a str.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filepath |
str
|
A filepath to your SQL file. |
required |
jinja_args |
dict
|
If not None, will pass the read in SQL file through a jinja template to render the template. Otherwise will just return the SQL file as is. Defaults to None. |
None
|
kwargs |
passed to the open() call. |
{}
|
Source code in pydbtools/_sql_render.py
render_sql_template(sql, jinja_args)
Takes a SQL file templated with Jinja and then injects arguments. Returns the injected SQL.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sql_file |
str
|
Path to SQL file |
required |
args |
dict
|
Arguments that is referenced in the SQL file |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
SQL string that has args rendered into it |