@hpcc-js/wasm-duckdb 1.13.1 → 1.14.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.13.1",
3
+ "version": "1.14.0",
4
4
  "description": "hpcc-js - WASM DuckDB",
5
5
  "type": "module",
6
6
  "exports": {
@@ -38,7 +38,7 @@
38
38
  "update-major": "npx -y npm-check-updates -u"
39
39
  },
40
40
  "devDependencies": {
41
- "@hpcc-js/esbuild-plugins": "1.7.0",
41
+ "@hpcc-js/esbuild-plugins": "1.8.0",
42
42
  "@hpcc-js/wasm-util": "1.0.0"
43
43
  },
44
44
  "keywords": [
@@ -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": "11395f5acfc865accde71905509bb45d5c79b11b"
58
+ "gitHead": "e34abaa76d55e43967e9da38228c28d75dd4d43a"
59
59
  }
package/src/duckdb.ts CHANGED
@@ -229,13 +229,61 @@ export class DuckDB extends MainModuleEx<MainModule> {
229
229
  registerFile(path: string, content: Uint8Array): void {
230
230
  const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
231
231
  const split = normalizedPath.lastIndexOf("/");
232
- const dir = split > 0 ? normalizedPath.substring(0, split) : "/";
233
- if (dir.length > 1 && this._module.FS_createPath) {
234
- this._module.FS_createPath(dir, true, true);
232
+ if (split > 0) {
233
+ const dir = normalizedPath.substring(0, split);
234
+ const parts = dir.split("/");
235
+ let currentPath = "/";
236
+ for (const part of parts) {
237
+ if (part && this._module.FS_createPath) {
238
+ this._module.FS_createPath(currentPath, part, true, true);
239
+ currentPath = currentPath === "/" ? "/" + part : currentPath + "/" + part;
240
+ }
241
+ }
235
242
  }
236
243
  this._module.FS_createDataFile(normalizedPath, undefined, content, true, true, true);
237
244
  }
238
245
 
246
+ /**
247
+ * Unregisters and removes a file from the virtual file system.
248
+ *
249
+ * This removes a file that was previously registered using {@link registerFile} or
250
+ * {@link registerFileString}. Once unregistered, the file will no longer be accessible
251
+ * to DuckDB queries.
252
+ *
253
+ * The path is normalized to remove leading slashes before removal.
254
+ *
255
+ * @param path - The path of the file to remove (e.g., "data/users.csv")
256
+ *
257
+ * @example
258
+ * ```ts
259
+ * const duckdb = await DuckDB.load();
260
+ *
261
+ * // Register a file
262
+ * duckdb.registerFileString("temp.csv", "id,name\n1,Alice");
263
+ *
264
+ * const connection = duckdb.connect();
265
+ * let result = connection.query("SELECT * FROM read_csv_auto('temp.csv')");
266
+ * console.log(result.rowCount()); // 1
267
+ * result.delete();
268
+ *
269
+ * // Unregister the file
270
+ * duckdb.unregisterFile("temp.csv");
271
+ *
272
+ * // File is no longer accessible
273
+ * try {
274
+ * result = connection.query("SELECT * FROM read_csv_auto('temp.csv')");
275
+ * } catch (error) {
276
+ * console.error("File not found"); // Error: file not accessible
277
+ * }
278
+ *
279
+ * connection.delete();
280
+ * ```
281
+ */
282
+ unregisterFile(path: string): void {
283
+ const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
284
+ this._module.FS_unlink(normalizedPath);
285
+ }
286
+
239
287
  /**
240
288
  * Registers a text file in the virtual file system.
241
289
  *
package/types/duckdb.d.ts CHANGED
@@ -190,6 +190,43 @@ export declare class DuckDB extends MainModuleEx<MainModule> {
190
190
  * ```
191
191
  */
192
192
  registerFile(path: string, content: Uint8Array): void;
193
+ /**
194
+ * Unregisters and removes a file from the virtual file system.
195
+ *
196
+ * This removes a file that was previously registered using {@link registerFile} or
197
+ * {@link registerFileString}. Once unregistered, the file will no longer be accessible
198
+ * to DuckDB queries.
199
+ *
200
+ * The path is normalized to remove leading slashes before removal.
201
+ *
202
+ * @param path - The path of the file to remove (e.g., "data/users.csv")
203
+ *
204
+ * @example
205
+ * ```ts
206
+ * const duckdb = await DuckDB.load();
207
+ *
208
+ * // Register a file
209
+ * duckdb.registerFileString("temp.csv", "id,name\n1,Alice");
210
+ *
211
+ * const connection = duckdb.connect();
212
+ * let result = connection.query("SELECT * FROM read_csv_auto('temp.csv')");
213
+ * console.log(result.rowCount()); // 1
214
+ * result.delete();
215
+ *
216
+ * // Unregister the file
217
+ * duckdb.unregisterFile("temp.csv");
218
+ *
219
+ * // File is no longer accessible
220
+ * try {
221
+ * result = connection.query("SELECT * FROM read_csv_auto('temp.csv')");
222
+ * } catch (error) {
223
+ * console.error("File not found"); // Error: file not accessible
224
+ * }
225
+ *
226
+ * connection.delete();
227
+ * ```
228
+ */
229
+ unregisterFile(path: string): void;
193
230
  /**
194
231
  * Registers a text file in the virtual file system.
195
232
  *
@@ -127,6 +127,7 @@ export interface Connection extends ClassHandle {
127
127
  getQueryProgress(): number;
128
128
  prepare(_0: EmbindString): PreparedStatement | null;
129
129
  query(_0: EmbindString): MaterializedQueryResult | null;
130
+ queryToJSON(_0: EmbindString): string;
130
131
  }
131
132
 
132
133
  export interface DuckDB extends ClassHandle {