Skip to content

Commit

Permalink
Add getD1Database(dbName) using getPlatformProxy
Browse files Browse the repository at this point in the history
  • Loading branch information
acusti committed Jul 25, 2024
1 parent 9889492 commit fe766b9
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/superflare/cli/d1-database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof import("wrangler")>(
"wrangler",
logger
);
const { env } = await getPlatformProxy({ experimentalJsonConfig: true });
return env[dbName] as D1DatabaseType | undefined;
}

0 comments on commit fe766b9

Please sign in to comment.