diff --git a/src/adapter.ts b/src/adapter.ts index b1752ef..731b9bb 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); @@ -143,14 +109,8 @@ 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); - } + // Schema-declared types may be available. Will be `null` for e.g. computed columns or expressions + const declaredTypes: Array = stmt.declaredTypes; const resultSet = { declaredTypes, @@ -445,4 +405,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 +}