From ae53a19440fa647851f123026500d1eca87fb5c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Rish=C3=B8j?= Date: Thu, 11 Sep 2025 21:46:33 +0200 Subject: [PATCH 1/3] use native `declaredTypes` of `Statement` --- src/adapter.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/adapter.ts b/src/adapter.ts index b1752ef..c7fe0d7 100644 --- a/src/adapter.ts +++ b/src/adapter.ts @@ -144,13 +144,7 @@ class BunSQLiteQueryable implements SqlQueryable { } // Try to get proper column types from table schema - let declaredTypes: Array; - const tableName = this.getTableFromQuery(query.sql); - if (tableName) { - declaredTypes = await this.getColumnTypes(tableName, columns); - } else { - declaredTypes = columns.map((col: any) => null); - } + const declaredTypes: Array = stmt.declaredTypes; const resultSet = { declaredTypes, @@ -445,4 +439,4 @@ function configureWALMode(db: Database, walConfig: boolean | WALConfig): void { db.exec(`PRAGMA busy_timeout = ${config.busyTimeout};`); debug(`Busy timeout set to: ${config.busyTimeout}ms`); } -} \ No newline at end of file +} From 88bff28e770603609049283db3bcda22a4be6033 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Rish=C3=B8j?= Date: Thu, 11 Sep 2025 21:49:01 +0200 Subject: [PATCH 2/3] remove unused methods --- src/adapter.ts | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/src/adapter.ts b/src/adapter.ts index c7fe0d7..28bb37c 100644 --- a/src/adapter.ts +++ b/src/adapter.ts @@ -93,40 +93,6 @@ class BunSQLiteQueryable implements SqlQueryable { } } - private getTableFromQuery(sql: string): string | null { - // Simple regex to extract table name from SELECT queries - // This handles common cases like SELECT ... FROM table, SELECT ... FROM "table", etc. - const match = sql.match(/\bFROM\s+(?:`([^`]+)`|"([^"]+)"|(\w+))/i); - return match ? (match[1] || match[2] || match[3]) : null; - } - - private async getColumnTypes(tableName: string, columnNames: string[]): Promise> { - try { - const tableInfoStmt = this.db.query(`PRAGMA table_info(${tableName})`); - const tableInfo = tableInfoStmt.all() as Array<{ - cid: number; - name: string; - type: string; - notnull: number; - dflt_value: string | null; - pk: number; - }>; - - // Create a map of column names to types - const typeMap = new Map(); - tableInfo.forEach(col => { - typeMap.set(col.name, col.type); - }); - - // Return types in the same order as columnNames - return columnNames.map(name => typeMap.get(name) || null); - } catch (e) { - debug("Failed to get column types for table %s: %O", tableName, e); - // Fall back to null types if we can't get schema info - return columnNames.map(() => null); - } - } - private async performIO(query: SqlQuery): Promise { try { const stmt = this.db.query(query.sql); From f1c1bd19ccadc67e821ecb2ab13d33ae31ff553e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Rish=C3=B8j?= Date: Thu, 11 Sep 2025 21:51:47 +0200 Subject: [PATCH 3/3] comment --- src/adapter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/adapter.ts b/src/adapter.ts index 28bb37c..731b9bb 100644 --- a/src/adapter.ts +++ b/src/adapter.ts @@ -109,7 +109,7 @@ class BunSQLiteQueryable implements SqlQueryable { }); } - // Try to get proper column types from table schema + // Schema-declared types may be available. Will be `null` for e.g. computed columns or expressions const declaredTypes: Array = stmt.declaredTypes; const resultSet = {