Skip to content

Commit a82646f

Browse files
committed
for
1 parent c529b8b commit a82646f

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

packages/duckdb-wasm/src/bindings/runtime_browser.ts

+18-13
Original file line numberDiff line numberDiff line change
@@ -142,22 +142,27 @@ export const BROWSER_RUNTIME: DuckDBRuntime & {
142142
dirHandle = await dirHandle.getDirectoryHandle(folder, { create: isReadWrite });
143143
}
144144
}
145-
const fileHandle = await dirHandle.getFileHandle(fileName, { create: false }).catch(e => {
145+
let fileHandle:FileSystemFileHandle;
146+
try {
147+
fileHandle = await dirHandle.getFileHandle(fileName, { create: false });
148+
} catch (e:any) {
146149
if (e?.name === 'NotFoundError') {
147150
if (isReadWrite) {
148-
console.debug(`File ${path} does not exists yet, creating...`);
149-
return dirHandle.getFileHandle(fileName, { create: true });
151+
console.debug(`File ${ path } does not exists yet, creating...`);
152+
fileHandle = await dirHandle.getFileHandle(fileName, { create: true });
153+
} else {
154+
console.debug(`File ${ path } does not exists, aborting as we are in read-only mode`);
155+
throw e;
150156
}
151-
console.debug(`File ${path} does not exists, aborting as we are in read-only mode`);
157+
} else {
158+
throw e;
152159
}
153-
throw e;
154-
});
160+
}
155161
try {
156-
let createSyncAccessMode:'read-only' | 'readwrite' | 'readwrite-unsafe' = "read-only";
157-
if( isReadWrite ){
158-
createSyncAccessMode = isReadWrite ? "readwrite" : "readwrite-unsafe";
159-
}
160-
const handle = await fileHandle.createSyncAccessHandle(createSyncAccessMode);
162+
let syncAccessHandleMode:FileSystemSyncAccessHandleMode = isReadWrite ? "readwrite" : "readwrite-unsafe";
163+
const handle = await fileHandle.createSyncAccessHandle({
164+
mode : syncAccessHandleMode
165+
});
161166
BROWSER_RUNTIME._preparedHandles[path] = handle;
162167
return {
163168
path,
@@ -178,10 +183,10 @@ export const BROWSER_RUNTIME: DuckDBRuntime & {
178183
throw new Error(`Unsupported protocol ${protocol} for paths ${filePaths} with protocol ${protocol}`);
179184
},
180185
/** Prepare a file handle that could only be acquired asynchronously */
181-
async prepareDBFileHandle(dbPath: string, protocol: DuckDBDataProtocol, accessMode: DuckDBAccessMode): Promise<PreparedDBFileHandle[]> {
186+
async prepareDBFileHandle(dbPath: string, protocol: DuckDBDataProtocol, accessMode: DuckDBAccessMode, multiWindowMode:boolean): Promise<PreparedDBFileHandle[]> {
182187
if (protocol === DuckDBDataProtocol.BROWSER_FSACCESS && this.prepareFileHandles) {
183188
const filePaths = [dbPath, `${dbPath}.wal`];
184-
return this.prepareFileHandles(filePaths, protocol, accessMode);
189+
return this.prepareFileHandles(filePaths, protocol, accessMode, multiWindowMode);
185190
}
186191
throw new Error(`Unsupported protocol ${protocol} for path ${dbPath} with protocol ${protocol}`);
187192
},

packages/duckdb-wasm/test/filesystem.test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ export function testFilesystem(
237237
//);
238238
//expect(schema_script.trim()).toEqual(`CREATE TABLE foo(v BIGINT);`);
239239
//expect(csv_buffer.trim()).toEqual(`1\n2\n3\n4\n5`);
240+
241+
await conn.query('DROP TABLE foo');
240242
});
241243

242244
it('Generate Series as Parquet', async () => {
@@ -264,6 +266,8 @@ export function testFilesystem(
264266
expect(content.nullCount).toEqual(0);
265267
expect(content.numRows).toEqual(5);
266268
expect(content.getChildAt(0)?.toArray()).toEqual(new Int32Array([1, 2, 3, 4, 5]));
269+
270+
await conn.query('DROP TABLE foo');
267271
});
268272
});
269273

0 commit comments

Comments
 (0)