Database Connections 🔌¶
Jetbase supports multiple databases. This guide covers how to connect to each supported database using a SQLAlchemy url.
PostgreSQL¶
Installing a Driver¶
PostgreSQL requires a database driver. Examples:
Connection String¶
Example¶
With a specific schema:
# jetbase/env.py
sqlalchemy_url = "postgresql://myuser:mypassword@localhost:5432/myapp"
postgres_schema = "public"
Snowflake¶
Snowflake is a cloud-based data warehouse. Jetbase supports both username/password and key pair authentication.
Installing the Driver¶
Snowflake requires additional dependencies. Install Jetbase with the Snowflake extra:
Connection String Format¶
| Component | Description |
|---|---|
username |
Your Snowflake username |
password |
Your Snowflake password (omit for key pair auth) |
account |
Your Snowflake account identifier (e.g., abc12345.us-east-1) |
database |
Target database name |
schema |
Target schema name |
warehouse |
Compute warehouse to use |
Username & Password Authentication¶
The simplest way to connect is with username and password:
# jetbase/env.py
sqlalchemy_url = "snowflake://myuser:mypassword@myaccount.us-east-1/my_db/public?warehouse=COMPUTE_WH"
Key Pair Authentication¶
For enhanced security, Snowflake supports key pair authentication. To use it, omit the password from your connection string and configure your private key.
Step 1: Create a connection string without a password:
# jetbase/env.py
sqlalchemy_url = "snowflake://myuser@myaccount.us-east-1/my_db/public?warehouse=COMPUTE_WH"
Step 2: Configure your private key as an environment variable:
# Set the private key (PEM format)
export JETBASE_SNOWFLAKE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASC...
-----END PRIVATE KEY-----"
# Optional: if your private key is encrypted
export JETBASE_SNOWFLAKE_PRIVATE_KEY_PASSWORD="your-key-password"
Tip
It's best to read your private key file directly into the environment variable locally:
SQLite¶
Connection String¶
SQLite doesn't require any additional drivers. Just connect with the connection string.
Examples¶
Relative path (relative to where you run Jetbase):
In-memory database (useful for testing):
MySQL¶
Installing a Driver¶
MySQL requires the PyMySQL driver:
Connection String¶
Example¶
Databricks¶
Installing the Driver¶
Databricks requires additional dependencies. Install Jetbase with the Databricks extra:
Connection String Format¶
sqlalchemy_url = "databricks://token:ACCESS_TOKEN@HOSTNAME?http_path=HTTP_PATH&catalog=CATALOG&schema=SCHEMA"
| Component | Description |
|---|---|
ACCESS_TOKEN |
Your Databricks personal access token |
HOSTNAME |
Your Databricks workspace hostname (e.g., adb-1234567890123456.cloud.databricks.com) |
HTTP_PATH |
The HTTP path to your SQL warehouse or cluster (e.g., /sql/1.0/warehouses/abc) |
CATALOG |
The Unity Catalog name to use |
SCHEMA |
The schema name within the catalog |
Example¶
# jetbase/env.py
sqlalchemy_url = "databricks://token:dapi1234567890abcdef@adb-1234567890123456.cloud.databricks.comt?http_path=/sql/1.0/warehouses/abc123def456&catalog=main&schema=default"
ClickHouse¶
ClickHouse is a high-performance column-oriented OLAP database. Jetbase supports ClickHouse for managing schema migrations.
Installing the Driver¶
ClickHouse requires additional dependencies. Install Jetbase with the ClickHouse extra:
Connection String Format¶
| Component | Description |
|---|---|
username |
Your ClickHouse username (default: default) |
password |
Your ClickHouse password (can be empty for local development) |
host |
ClickHouse server hostname |
port |
HTTP port (default: 8123) |
database |
Target database name (default: default) |
Example¶
Important Notes¶
ClickHouse
ClickHouse does not support migration locking.