BaseTen
Search…
🔗
Connecting to existing databases
To be able to communicate with your existing data sources (e.g. MySQL, Postgres, BigQuery, Snowflake, Redis) you have to follow two steps: 1. Create a database connection On the Settings page, "Database connections" tab, press the "New" button, select the type of the database, and answer the config and auth questions. Name it something meaningful; you'll be using this name. 2. In your Code block and Decision nodes you can access a database 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 modified 4mo ago
Copy link