diff --git a/docs/pages/product/configuration/data-sources/duckdb.mdx b/docs/pages/product/configuration/data-sources/duckdb.mdx index b0e05acba0..faa5b22f09 100644 --- a/docs/pages/product/configuration/data-sources/duckdb.mdx +++ b/docs/pages/product/configuration/data-sources/duckdb.mdx @@ -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=`. 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] | ✅ | ✅ | diff --git a/docs/pages/reference/configuration/environment-variables.mdx b/docs/pages/reference/configuration/environment-variables.mdx index 95d7f1ea64..5feda05329 100644 --- a/docs/pages/reference/configuration/environment-variables.mdx +++ b/docs/pages/reference/configuration/environment-variables.mdx @@ -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. diff --git a/packages/cubejs-backend-shared/src/env.ts b/packages/cubejs-backend-shared/src/env.ts index 03b2fddb99..398263c8da 100644 --- a/packages/cubejs-backend-shared/src/env.ts +++ b/packages/cubejs-backend-shared/src/env.ts @@ -1408,6 +1408,16 @@ const variables: Record any> = { ] ), + duckdbDatabasePath: ({ + dataSource + }: { + dataSource: string, + }) => ( + process.env[ + keyByDataSource('CUBEJS_DB_DUCKDB_DATABASE_PATH', dataSource) + ] + ), + duckdbS3Region: ({ dataSource }: { diff --git a/packages/cubejs-duckdb-driver/src/DuckDBDriver.ts b/packages/cubejs-duckdb-driver/src/DuckDBDriver.ts index 413bf01411..1a80556363 100644 --- a/packages/cubejs-duckdb-driver/src/DuckDBDriver.ts +++ b/packages/cubejs-duckdb-driver/src/DuckDBDriver.ts @@ -57,8 +57,11 @@ export class DuckDBDriver extends BaseDriver implements DriverInterface { protected async init(): Promise { 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 = promisify(defaultConnection.exec).bind(defaultConnection) as any;