Connecting to existing databases

Communicate with your database connection from your code blocks.

Create a database connection to communicate with your existing data sources (e.g. MySQL, PostgreSQL, BigQuery, Snowflake, Redis) from the "Connections" tab on the "Data" page.

Once the connection is established, you can access a database in your Code Decision blocks using the context arg:

  • context.run_query('db_connection_name', 'select * from my_table') returns a dict; the query results are under the 'results' key.

    • For safe parameterized query execution use Jinja templating (notice the {{}}) in the following example: context.run_query('db_connection_name', 'select * from my_table where id = {{id}}', {'id': some_id})

  • context.client('db_connection_name') returns a native client for the database connection. This gives you more flexibility, but also more responsibility. Don't go dropping tables or introducing SQL injection possibilities.

Last updated