From 49c32a648c41e89fbe150b6c255e459a822ea5b4 Mon Sep 17 00:00:00 2001 From: "Visal .In" Date: Wed, 18 Sep 2024 20:31:10 +0700 Subject: [PATCH] fixing cloudflare driver --- src/drivers/cloudflare-d1-driver.ts | 1 + src/drivers/sqlite-base-driver.ts | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/drivers/cloudflare-d1-driver.ts b/src/drivers/cloudflare-d1-driver.ts index e707cbe..0cca72f 100644 --- a/src/drivers/cloudflare-d1-driver.ts +++ b/src/drivers/cloudflare-d1-driver.ts @@ -69,6 +69,7 @@ function transformRawResult(raw: CloudflareResult): DatabaseResultSet { } export default class CloudflareD1Driver extends SqliteLikeBaseDriver { + supportPragmaList: boolean = false; protected headers: Record = {}; protected url: string; diff --git a/src/drivers/sqlite-base-driver.ts b/src/drivers/sqlite-base-driver.ts index 1c6de10..4faf6ea 100644 --- a/src/drivers/sqlite-base-driver.ts +++ b/src/drivers/sqlite-base-driver.ts @@ -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, '""')}"`; } @@ -122,9 +124,17 @@ export abstract class SqliteLikeBaseDriver extends CommonSQLImplement { } async schemas(): Promise { - 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(