Integrate with Microsoft SQL Server data sources.
Chalk supports Microsoft SQL Server
and Azure SQL Database
as a SQL source.
You can configure the Microsoft SQL Server-specific
options using the MSSQLSource 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 Microsoft SQL Server database.
Chalk supports three authentication methods:
SQL Authentication - Traditional username and password authentication
Azure AD Managed Identity - When running in Azure (such as in AKS or Azure VMs), Chalk can automatically authenticate using Managed Identity. Simply omit authentication credentials when configuring your source.
Azure AD Service Principal - For authentication using an Azure AD application, provide client_id, client_secret, and tenant_id.
If you have only one Microsoft SQL Server 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 MSSQLSource
mssql = MSSQLSource()
@online
def fn(...) -> ...:
return mssql.query(...).first()from chalk.sql import MSSQLSource
risk = MSSQLSource(name="RISK")
marketing = MSSQLSource(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 MSSQL_HOST will be injected as RISK_MSSQL_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 MSSQLSource
mssql = MSSQLSource(
host=os.getenv("MSSQL_HOST"),
port=os.getenv("MSSQL_TCP_PORT"),
db=os.getenv("MSSQL_DATABASE"),
user=os.getenv("MSSQL_USER"),
password=os.getenv("MSSQL_PWD"),
)
@online
def fn(...) -> ...:
return mssql.query(...).first()import os
from chalk.sql import MSSQLSource
mssql = MSSQLSource(
host=os.getenv("MSSQL_HOST"),
port=os.getenv("MSSQL_TCP_PORT"),
db=os.getenv("MSSQL_DATABASE"),
client_id=os.getenv("MSSQL_CLIENT_ID"),
client_secret=os.getenv("MSSQL_CLIENT_SECRET"),
tenant_id=os.getenv("MSSQL_TENANT_ID"),
)
@online
def fn(...) -> ...:
return mssql.query(...).first()import os
from chalk.sql import MSSQLSource
# Only connection details needed - authentication is automatic
mssql = MSSQLSource(
host=os.getenv("MSSQL_HOST"),
port=os.getenv("MSSQL_TCP_PORT"),
db=os.getenv("MSSQL_DATABASE"),
)
@online
def fn(...) -> ...:
return mssql.query(...).first()