Integrations
Integrate with SQL data sources.
Chalk supports PostgreSQL
as a SQL source.
You can configure the PostgreSQL-specific
options using the PostgreSQLSource
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 PostgreSQL database:
Add a PostgreSQL integration. These parameters will also be available as environment variables.
If you have only one PostgreSQL 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 PostgreSQLSource
pg = PostgreSQLSource()
@online
def resolver_fn(...) -> ...:
return pg.query(...).first()
from chalk.sql import PostgreSQLSource
risk_pg = PostgreSQLSource(name="RISK_PG")
marketing_pg = PostgreSQLSource(name="MARKETING_PG")
@online
def risk_resolver(...) -> ...:
return risk_pg.query(...).first()
@online
def marketing_resolver(...) -> ...:
return marketing_pg.query(...).first()
Named integrations inject environment variables with the standard names prefixed by the integration name. For example, if your integration is called RISK_PG
, then the variable PGPORT
will be injected as RISK_PG_PGPORT
. The first integration of a given kind will also create the un-prefixed environment variable (ie. both PGPORT
and RISK_PG_PGPORT
).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 PostgreSQLSource
pg = PostgreSQLSource(
host=os.getenv("PGHOST"),
port=os.getenv("PGPORT"),
db=os.getenv("PGDATABASE"),
user=os.getenv("PGUSER"),
password=os.getenv("PGPASSWORD"),
)
@online
def resolver_fn(...) -> ...:
return pg.query(...).first()