Skip to content

Commit

Permalink
fixing cloudflare driver
Browse files Browse the repository at this point in the history
  • Loading branch information
invisal committed Sep 18, 2024
1 parent 73dfa3d commit 49c32a6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/drivers/cloudflare-d1-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function transformRawResult(raw: CloudflareResult): DatabaseResultSet {
}

export default class CloudflareD1Driver extends SqliteLikeBaseDriver {
supportPragmaList: boolean = false;
protected headers: Record<string, string> = {};
protected url: string;

Expand Down
16 changes: 13 additions & 3 deletions src/drivers/sqlite-base-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import CommonSQLImplement from "./common-sql-imp";
import generateSqlSchemaChange from "@/components/lib/sql-generate.schema";

export abstract class SqliteLikeBaseDriver extends CommonSQLImplement {
supportPragmaList = true;

escapeId(id: string) {
return `"${id.replace(/"/g, '""')}"`;
}
Expand Down Expand Up @@ -122,9 +124,17 @@ export abstract class SqliteLikeBaseDriver extends CommonSQLImplement {
}

async schemas(): Promise<DatabaseSchemas> {
const databaseList = (await this.query("PRAGMA database_list;")).rows as {
name: string;
}[];
let databaseList = [{ name: "main" }];

try {
if (this.supportPragmaList) {
databaseList = (await this.query("PRAGMA database_list;")).rows as {
name: string;
}[];
}
} catch {
console.error("PRAGMA database_list statement is not supported");
}

const tableListPerDatabase = await this.transaction(
databaseList.map(
Expand Down

0 comments on commit 49c32a6

Please sign in to comment.