piper.text.set_sql_file

piper.text.set_sql_file(from_file=None, to_file=None, template_values=True)[source]

Set SQL file text to ‘template’ substitutional values

Examples

Set/replace existing SQL text file to template format:

project_dir = Path.home() / 'documents'

from_file = project_dir / 'Scratchpad.sql'
to_file = project_dir / 'Scratchpad_revised.sql'
set_sql_file(from_file, to_file, template_values=True)

To convert a ‘templated’ sql text file to use hardcoded schema values:

from_file = project_dir / 'Scratchpad_revised.sql'
to_file = project_dir / 'Scratchpad_revised2.sql'

template_values = {'{schema}': 'eudta', '{schema_ctl}': 'euctl'}
set_sql_file(from_file, to_file, template_values)
Parameters
  • from_file – source file containing sql text to be converted

  • to_file – target file to contain substituted text

  • template_values – True (convert sql text to use ‘template’ variables) or, string value (a dictionary of key/values each containing a regex statement and replacement values

Returns

Return type

None