@hpcc-js/wasm-duckdb 1.14.0 → 1.15.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hpcc-js/wasm-duckdb",
3
- "version": "1.14.0",
3
+ "version": "1.15.0",
4
4
  "description": "hpcc-js - WASM DuckDB",
5
5
  "type": "module",
6
6
  "exports": {
@@ -55,5 +55,5 @@
55
55
  },
56
56
  "homepage": "https://hpcc-systems.github.io/hpcc-js-wasm/",
57
57
  "license": "Apache-2.0",
58
- "gitHead": "e34abaa76d55e43967e9da38228c28d75dd4d43a"
58
+ "gitHead": "81504905bd26f44c1e68b31760269dee081c0cbb"
59
59
  }
package/src/duckdb.ts CHANGED
@@ -91,20 +91,59 @@ const textEncoder = new TextEncoder();
91
91
  * @see [DuckDB Documentation](https://duckdb.org/docs/)
92
92
  * @see [DuckDB GitHub](https://github.com/duckdb/duckdb)
93
93
  */
94
-
95
-
96
-
97
- export class DuckDB extends MainModuleEx<MainModule> {
94
+ export class DuckDB extends MainModuleEx<MainModule> implements Disposable {
98
95
 
99
96
  db: CPPDuckDB
100
97
 
101
98
  private constructor(_module: MainModule) {
102
99
  super(_module);
103
100
  this.db = this._module.create()!;
101
+ // Special home directory for web_user (needed for some extensions)
104
102
  const { FS_createPath } = this._module;
105
103
  FS_createPath("/", "home/web_user", true, true);
106
104
  }
107
105
 
106
+ /**
107
+ * Disposes of the DuckDB database instance and releases resources.
108
+ *
109
+ * This method should be called when you're done using the database to free up
110
+ * memory and clean up resources. After calling dispose, the instance should not be used.
111
+ *
112
+ * @example
113
+ * ```ts
114
+ * const duckdb = await DuckDB.load();
115
+ * const connection = duckdb.connect();
116
+ * // ... use the database ...
117
+ * connection.delete();
118
+ * duckdb.dispose();
119
+ * ```
120
+ *
121
+ * @example Using statement (TypeScript 5.2+)
122
+ * ```ts
123
+ * {
124
+ * using duckdb = await DuckDB.load();
125
+ * const connection = duckdb.connect();
126
+ * // ... use the database ...
127
+ * connection.delete();
128
+ * } // duckdb.dispose() is called automatically
129
+ * ```
130
+ */
131
+ dispose(): void {
132
+ try {
133
+ this.db?.terminate();
134
+ } finally {
135
+ this.db?.delete();
136
+ }
137
+ }
138
+
139
+ /**
140
+ * Symbol.dispose implementation for use with `using` declarations.
141
+ * @internal
142
+ */
143
+ [Symbol.dispose](): void {
144
+ this.dispose();
145
+ }
146
+
108
147
  /**
109
148
  * Loads and initializes the DuckDB WASM module.
110
149
  *
package/types/duckdb.d.ts CHANGED
@@ -85,9 +85,40 @@ import { MainModuleEx } from "@hpcc-js/wasm-util";
85
85
  * @see [DuckDB Documentation](https://duckdb.org/docs/)
86
86
  * @see [DuckDB GitHub](https://github.com/duckdb/duckdb)
87
87
  */
88
- export declare class DuckDB extends MainModuleEx<MainModule> {
88
+ export declare class DuckDB extends MainModuleEx<MainModule> implements Disposable {
89
89
  db: CPPDuckDB;
90
90
  private constructor();
91
+ /**
92
+ * Disposes of the DuckDB database instance and releases resources.
93
+ *
94
+ * This method should be called when you're done using the database to free up
95
+ * memory and clean up resources. After calling dispose, the instance should not be used.
96
+ *
97
+ * @example
98
+ * ```ts
99
+ * const duckdb = await DuckDB.load();
100
+ * const connection = duckdb.connect();
101
+ * // ... use the database ...
102
+ * connection.delete();
103
+ * duckdb.dispose();
104
+ * ```
105
+ *
106
+ * @example Using statement (TypeScript 5.2+)
107
+ * ```ts
108
+ * {
109
+ * using duckdb = await DuckDB.load();
110
+ * const connection = duckdb.connect();
111
+ * // ... use the database ...
112
+ * connection.delete();
113
+ * } // duckdb.dispose() is called automatically
114
+ * ```
115
+ */
116
+ dispose(): void;
117
+ /**
118
+ * Symbol.dispose implementation for use with `using` declarations.
119
+ * @internal
120
+ */
121
+ [Symbol.dispose](): void;
91
122
  /**
92
123
  * Loads and initializes the DuckDB WASM module.
93
124
  *