Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
e1arikawa committed Feb 20, 2025
1 parent 69f4375 commit 57ef254
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
6 changes: 4 additions & 2 deletions packages/duckdb-wasm/src/bindings/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ export interface DuckDBFilesystemConfig {

export interface DuckDBOPFSConfig {
/**
* Auto Opfs File Registration
* Defines how `opfs://` files are handled during SQL execution.
* - "auto": Automatically register `opfs://` files and drop them after execution.
* - "manual": Files must be manually registered and dropped.
*/
autoFileRegistration?: boolean;
fileHandling?: "auto" | "manual";
}

export enum DuckDBAccessMode {
Expand Down
8 changes: 4 additions & 4 deletions packages/duckdb-wasm/src/parallel/async_bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ export class AsyncDuckDB implements AsyncDuckDBBindings {

/** Run a query */
public async runQuery(conn: ConnectionID, text: string): Promise<Uint8Array> {
if( this.isOpenedOPFSAutoFileRegistration() ){
if( this.shouldOPFSFileHandling() ){
const files = await this.registerOPFSFileFromSQL(text);
try {
return await this._runQueryAsync(conn, text);
Expand Down Expand Up @@ -431,7 +431,7 @@ export class AsyncDuckDB implements AsyncDuckDBBindings {
text: string,
allowStreamResult: boolean = false,
): Promise<Uint8Array | null> {
if( this.isOpenedOPFSAutoFileRegistration() ){
if( this.shouldOPFSFileHandling() ){
const files = await this.registerOPFSFileFromSQL(text);
try {
return await this._startPendingQueryAsync(conn, text, allowStreamResult);
Expand Down Expand Up @@ -692,9 +692,9 @@ export class AsyncDuckDB implements AsyncDuckDBBindings {
await this.postTask(task);
}

private isOpenedOPFSAutoFileRegistration():boolean {
private shouldOPFSFileHandling():boolean {
if( isOPFSProtocol(this.config.path ?? "")){
return this.config.opfs?.autoFileRegistration ?? false;
return this.config.opfs?.fileHandling == "auto";
}
return false;
}
Expand Down
8 changes: 4 additions & 4 deletions packages/duckdb-wasm/test/opfs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ export function testOPFS(baseDir: string, bundle: () => duckdb.DuckDBBundle): vo
await db.reset();
await db.dropFile('test.parquet');
db.config.opfs = {
autoFileRegistration: true
fileHandling: "auto"
};
conn = await db.connect();
//2. send query
Expand All @@ -307,7 +307,7 @@ export function testOPFS(baseDir: string, bundle: () => duckdb.DuckDBBundle): vo
await db.reset();
await db.dropFile('test.parquet');
db.config.opfs = {
autoFileRegistration: true
fileHandling: "auto"
};
conn = await db.connect();
//2. send query
Expand All @@ -332,7 +332,7 @@ export function testOPFS(baseDir: string, bundle: () => duckdb.DuckDBBundle): vo
await db.reset();
await db.dropFile('datadir/test.parquet');
db.config.opfs = {
autoFileRegistration: true
fileHandling: "auto"
};
conn = await db.connect();
//2. send query
Expand Down Expand Up @@ -365,7 +365,7 @@ export function testOPFS(baseDir: string, bundle: () => duckdb.DuckDBBundle): vo
it('Copy CSV to OPFS + Load CSV', async () => {
//1. data preparation
db.config.opfs = {
autoFileRegistration: true
fileHandling: "auto"
};
await conn.query(`COPY ( SELECT 32 AS value ) TO 'opfs://file.csv'`);
await conn.query(`COPY ( SELECT 42 AS value ) TO 'opfs://file.csv'`);
Expand Down

0 comments on commit 57ef254

Please sign in to comment.