Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/pages/product/configuration/data-sources/duckdb.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ deployment][ref-demo-deployment] in Cube Cloud.
| `CUBEJS_DB_DUCKDB_MEMORY_LIMIT` | The maximum memory limit for DuckDB. Equivalent to `SET memory_limit=<MEMORY_LIMIT>`. Default is 75% of available RAM | A valid memory limit | ❌ | ✅ |
| `CUBEJS_DB_DUCKDB_SCHEMA` | The [default search schema][link-duckdb-configuration-ref] | A valid schema name | ❌ | ✅ |
| `CUBEJS_DB_DUCKDB_MOTHERDUCK_TOKEN` | The service token to use for connections to MotherDuck | A valid [MotherDuck service token][motherduck-docs-svc-token] | ❌ | ✅ |
| `CUBEJS_DB_DUCKDB_DATABASE_PATH` | The database filepath to use for connection to a local database. | A valid duckdb database file path | ❌ | ✅ |
| `CUBEJS_DB_DUCKDB_S3_ACCESS_KEY_ID` | The Access Key ID to use for database connections | A valid Access Key ID | ❌ | ✅ |
| `CUBEJS_DB_DUCKDB_S3_SECRET_ACCESS_KEY` | The Secret Access Key to use for database connections | A valid Secret Access Key | ❌ | ✅ |
| `CUBEJS_DB_DUCKDB_S3_ENDPOINT` | The S3 endpoint | A valid [S3 endpoint][duckdb-docs-s3-import] | ✅ | ✅ |
Expand Down
8 changes: 8 additions & 0 deletions docs/pages/reference/configuration/environment-variables.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,14 @@ MotherDuck.
| -------------------------------- | ---------------------- | --------------------- |
| A valid MotherDuck service token | N/A | N/A |

## `CUBEJS_DB_DUCKDB_DATABASE_PATH`

The database filepath to use for connection to a local database.

| Possible Values | Default in Development | Default in Production |
| --------------------------------- | ---------------------- | --------------------- |
| A valid duckdb database file path | N/A | N/A |

## `CUBEJS_DB_DUCKDB_S3_ACCESS_KEY_ID`

The AWS Access Key ID to use for S3 connections.
Expand Down
10 changes: 10 additions & 0 deletions packages/cubejs-backend-shared/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,16 @@ const variables: Record<string, (...args: any) => any> = {
]
),

duckdbDatabasePath: ({
dataSource
}: {
dataSource: string,
}) => (
process.env[
keyByDataSource('CUBEJS_DB_DUCKDB_DATABASE_PATH', dataSource)
]
),

duckdbS3Region: ({
dataSource
}: {
Expand Down
5 changes: 4 additions & 1 deletion packages/cubejs-duckdb-driver/src/DuckDBDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ export class DuckDBDriver extends BaseDriver implements DriverInterface {

protected async init(): Promise<InitPromise> {
const token = getEnv('duckdbMotherDuckToken', this.config);
const db_path = getEnv('duckdbDatabasePath', this.config);

const db = new Database(token ? `md:?motherduck_token=${token}&custom_user_agent=Cube/${version}` : ':memory:');
const db_url = db_path ? db_path : (token ? `md:?motherduck_token=${token}&custom_user_agent=Cube/${version}` : ':memory:');

const db = new Database(db_url);
// Under the hood all methods of Database uses internal default connection, but there is no way to expose it
const defaultConnection = db.connect();
const execAsync: (sql: string, ...params: any[]) => Promise<void> = promisify(defaultConnection.exec).bind(defaultConnection) as any;
Expand Down