@malloydata/db-duckdb 0.0.125-dev240212230553 → 0.0.125-dev240215152634

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,6 +17,7 @@ export declare class DuckDBConnection extends DuckDBCommon {
17
17
  private additionalExtensions;
18
18
  private databasePath;
19
19
  private workingDirectory;
20
+ private isMotherDuck;
20
21
  private motherDuckToken;
21
22
  private readOnly;
22
23
  connecting: Promise<void>;
@@ -35,6 +35,7 @@ class DuckDBConnection extends duckdb_common_1.DuckDBCommon {
35
35
  this.additionalExtensions = [];
36
36
  this.databasePath = ':memory:';
37
37
  this.workingDirectory = '.';
38
+ this.isMotherDuck = false;
38
39
  this.readOnly = false;
39
40
  this.connection = null;
40
41
  if (typeof arg === 'string') {
@@ -73,25 +74,28 @@ class DuckDBConnection extends duckdb_common_1.DuckDBCommon {
73
74
  if (this.databasePath === ':memory:') {
74
75
  this.readOnly = false;
75
76
  }
77
+ this.isMotherDuck =
78
+ this.databasePath.startsWith('md:') ||
79
+ this.databasePath.startsWith('motherduck:');
76
80
  this.connecting = this.init();
77
81
  }
78
82
  async init() {
79
83
  return new Promise(resolve => {
80
- let activeDB;
81
84
  if (this.databasePath in DuckDBConnection.activeDBs) {
82
- activeDB = DuckDBConnection.activeDBs[this.databasePath];
85
+ const activeDB = DuckDBConnection.activeDBs[this.databasePath];
83
86
  this.connection = activeDB.database.connect();
84
87
  activeDB.connections.push(this.connection);
85
88
  resolve();
86
89
  }
87
90
  else {
88
- if (this.databasePath.startsWith('md:')) {
91
+ if (this.isMotherDuck) {
89
92
  if (this.motherDuckToken) {
90
93
  process.env['motherduck_token'] = this.motherDuckToken;
91
94
  }
92
95
  if (!process.env['motherduck_token'] &&
93
96
  !process.env['MOTHERDUCK_TOKEN']) {
94
97
  this.setupError = new Error('Please set your MotherDuck Token');
98
+ // Resolve instead of error because errors cannot be caught.
95
99
  return resolve();
96
100
  }
97
101
  }
@@ -100,13 +104,17 @@ class DuckDBConnection extends duckdb_common_1.DuckDBCommon {
100
104
  this.setupError = err;
101
105
  }
102
106
  else {
103
- activeDB = {
104
- database,
105
- connections: [],
106
- };
107
- DuckDBConnection.activeDBs[this.databasePath] = activeDB;
108
- this.connection = activeDB.database.connect();
109
- activeDB.connections.push(this.connection);
107
+ this.connection = database.connect();
108
+ // Don't cache MotherDuck connections so they can
109
+ // pick up fresh credentials if necessary.
110
+ if (!this.isMotherDuck) {
111
+ const activeDB = {
112
+ database,
113
+ connections: [],
114
+ };
115
+ DuckDBConnection.activeDBs[this.databasePath] = activeDB;
116
+ activeDB.connections.push(this.connection);
117
+ }
110
118
  }
111
119
  resolve();
112
120
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/db-duckdb",
3
- "version": "0.0.125-dev240212230553",
3
+ "version": "0.0.125-dev240215152634",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -41,7 +41,7 @@
41
41
  },
42
42
  "dependencies": {
43
43
  "@malloydata/duckdb-wasm": "0.0.6",
44
- "@malloydata/malloy": "^0.0.125-dev240212230553",
44
+ "@malloydata/malloy": "^0.0.125-dev240215152634",
45
45
  "apache-arrow": "^13.0.0",
46
46
  "duckdb": "0.9.2",
47
47
  "web-worker": "^1.2.0"