Integrations
Integrate with MySQL data sources.
Chalk supports MySQL
as a SQL source.
You can configure the MySQL-specific
options using the MySQLSource
init args,
or configure the source through your dashboard, and
reference the source in your code.
On the dashboard, you can plug in the configuration for your MySQL database:
Add a MySQL integration.
If you have only one MySQL connection that you’d like to add to Chalk, you do not need to specify any arguments to construct the source in your code.
from chalk.sql import MySQLSource
mysql = MySQLSource()
@online
def fn(...) -> ...:
return mysql.query(...).first()
from chalk.sql import MySQLSource
risk = MySQLSource(name="RISK")
marketing = MySQLSource(name="MARKETING")
@online
def risk_resolver(...) -> ...:
return risk.query(...).first()
@online
def marketing_resolver(...) -> ...:
return marketing.query(...).first()
Named integrations inject environment variables with the standard names prefixed by the integration name. For example, if your integration is called RISK
, then the variable MYSQL_HOST
will be injected as RISK_MYSQL_HOST
. The first integration of a given kind will also create the un-prefixed environment variable (ie. both MYSQL_HOST
and RISK_MYSQL_HOST
).You can also configure the integration directly using environment variables on your local machine or from those added through the generic environment variable support.
import os
from chalk.sql import MySQLSource
mysql = MySQLSource(
host=os.getenv(...),
port=os.getenv(...),
db=os.getenv(...),
user=os.getenv(...),
password=os.getenv(...),
)
@online
def fn(...) -> ...:
return mysql.query(...).first()