Skip to content

Commit cb8ff4c

Browse files
Copilothuangyiirene
andcommitted
fix: Correct SQLite result array handling
- Fix table existence check to properly handle SQLite result arrays - Add array type guard for table listing query - Improve error message clarity for invalid table names Co-authored-by: huangyiirene <7665279+huangyiirene@users.noreply.github.com>
1 parent 9ec9760 commit cb8ff4c

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

packages/drivers/sql/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ export class SqlDriver implements Driver {
645645
[tableName]
646646
);
647647

648-
if (!tableExistsResult || tableExistsResult.length === 0) {
648+
if (!Array.isArray(tableExistsResult) || tableExistsResult.length === 0) {
649649
// If the table does not exist, there are no foreign keys to introspect.
650650
return foreignKeys;
651651
}
@@ -708,10 +708,10 @@ export class SqlDriver implements Driver {
708708

709709
// Validate that the sanitized table name exists in the database before using it in PRAGMA
710710
const tablesResult = await this.knex.raw("SELECT name FROM sqlite_master WHERE type = 'table'");
711-
const tableNames = tablesResult.map((row: any) => row.name);
711+
const tableNames = Array.isArray(tablesResult) ? tablesResult.map((row: any) => row.name) : [];
712712

713713
if (!tableNames.includes(safeTableName)) {
714-
console.warn('Could not introspect primary keys for SQLite table: table does not exist after sanitization.');
714+
console.warn('Could not introspect primary keys: table name contains invalid characters or table does not exist.');
715715
return primaryKeys;
716716
}
717717

0 commit comments

Comments
 (0)