From fe766b92036f3ad21870ed1d8e8d8f68c65c30a1 Mon Sep 17 00:00:00 2001 From: Andrew Patton Date: Thu, 25 Jul 2024 09:35:12 -0700 Subject: [PATCH] Add getD1Database(dbName) using getPlatformProxy --- packages/superflare/cli/d1-database.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/superflare/cli/d1-database.ts b/packages/superflare/cli/d1-database.ts index 87571318..87acb55d 100644 --- a/packages/superflare/cli/d1-database.ts +++ b/packages/superflare/cli/d1-database.ts @@ -12,3 +12,13 @@ export async function createD1Database( const db = new D1Database(new D1DatabaseAPI(sqliteDb)); return db as any as D1DatabaseType; } + +export async function getD1Database(dbName: string, logger = console.log) { + const { npxImport } = await import("npx-import"); + const { getPlatformProxy } = await npxImport( + "wrangler", + logger + ); + const { env } = await getPlatformProxy({ experimentalJsonConfig: true }); + return env[dbName] as D1DatabaseType | undefined; +}