From 43acf4f8a26fa6f459ce76850608dc01b6ce504a Mon Sep 17 00:00:00 2001 From: Rick Smit Date: Mon, 2 Oct 2023 09:29:53 +0200 Subject: [PATCH 1/2] add configuration options for DuckDB class --- packages/duckdb/src/DuckDB.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/duckdb/src/DuckDB.js b/packages/duckdb/src/DuckDB.js index 3528c93f..03ac4f45 100644 --- a/packages/duckdb/src/DuckDB.js +++ b/packages/duckdb/src/DuckDB.js @@ -3,7 +3,7 @@ import { mergeBuffers } from './merge-buffers.js'; const TEMP_DIR = '.duckdb'; -const CONFIG = [ +const INIT_STATEMENTS = [ `PRAGMA temp_directory='${TEMP_DIR}'`, `INSTALL arrow`, `INSTALL httpfs`, @@ -12,10 +12,14 @@ const CONFIG = [ ]; export class DuckDB { - constructor(path = ':memory:') { - this.db = new duckdb.Database(path); + constructor( + path = ':memory:', + config = {}, + initStatementsOverride = null + ) { + this.db = new duckdb.Database(path, config); this.con = this.db.connect(); - this.exec(CONFIG.join(';\n')); + this.exec((initStatementsOverride ?? INIT_STATEMENTS).join(';\n')); } close() { From 2f431b3b69cf40f4832b6da2fac1c3cbe9e0bf28 Mon Sep 17 00:00:00 2001 From: Jeffrey Heer Date: Thu, 28 Dec 2023 13:15:31 -0600 Subject: [PATCH 2/2] Refactor DuckDB init statements. --- packages/duckdb/src/DuckDB.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/duckdb/src/DuckDB.js b/packages/duckdb/src/DuckDB.js index 03ac4f45..1d109a62 100644 --- a/packages/duckdb/src/DuckDB.js +++ b/packages/duckdb/src/DuckDB.js @@ -3,23 +3,23 @@ import { mergeBuffers } from './merge-buffers.js'; const TEMP_DIR = '.duckdb'; -const INIT_STATEMENTS = [ +const DEFAULT_INIT_STATEMENTS = [ `PRAGMA temp_directory='${TEMP_DIR}'`, `INSTALL arrow`, `INSTALL httpfs`, `LOAD arrow`, `LOAD httpfs` -]; +].join(';\n'); export class DuckDB { constructor( path = ':memory:', config = {}, - initStatementsOverride = null + initStatements = DEFAULT_INIT_STATEMENTS ) { this.db = new duckdb.Database(path, config); this.con = this.db.connect(); - this.exec((initStatementsOverride ?? INIT_STATEMENTS).join(';\n')); + this.exec(initStatements); } close() {