History

Remove PGlite fallback from cloud app (#120)

Cloud always uses Postgres via Hyperdrive or DATABASE_URL.

Rhys Sullivan committed 7 months ago

Commit 2f65dae1 parent 22129163 files · +9 −29Browse files

Showing the changes to apps/cloud/src/services (1 of 3 files). Show all

Unified · Split

apps/cloud/src/services/db.ts+9−26
@@ -30,6 +30,11 @@ const resolveHyperdriveUrl = Effect.tryPromise({ · 29 unmodified lines
30 30
31const resolveConnectionString = resolveHyperdriveUrl.pipe(31const resolveConnectionString = resolveHyperdriveUrl.pipe(
32 Effect.map((url) => url ?? (server.DATABASE_URL || undefined)),32 Effect.map((url) => url ?? (server.DATABASE_URL || undefined)),
33 Effect.flatMap((url) =>
34 url
35 ? Effect.succeed(url)
36 : Effect.fail(new Error("No database connection string available (set DATABASE_URL or configure Hyperdrive)")),
37 ),
33);38);
34 39
35// ---------------------------------------------------------------------------40// ---------------------------------------------------------------------------
@@ -47,22 +52,6 @@ const acquirePostgres = (connectionString: string) => · 11 unmodified lines
47const releasePostgres = ({ pool }: { pool: { end: () => Promise<void> } }) =>52const releasePostgres = ({ pool }: { pool: { end: () => Promise<void> } }) =>
48 Effect.promise(() => pool.end()).pipe(Effect.orElseSucceed(() => undefined));53 Effect.promise(() => pool.end()).pipe(Effect.orElseSucceed(() => undefined));
49 54
50// ---------------------------------------------------------------------------
51// PGlite — local dev fallback
52// ---------------------------------------------------------------------------
53
54const acquirePglite = Effect.tryPromise(async () => {
55 const { PGlite } = await import("@electric-sql/pglite");
56 const { drizzle } = await import("drizzle-orm/pglite");
57 const client = new PGlite(server.PGLITE_DATA_DIR);
58 return { db: drizzle(client, { schema }) as DrizzleDb, client };
59});
60
61const releasePglite = ({ client }: { client: { close?: () => Promise<void> } }) =>
62 Effect.promise(() => client.close?.() ?? Promise.resolve()).pipe(
63 Effect.orElseSucceed(() => undefined),
64 );
65
66// ---------------------------------------------------------------------------55// ---------------------------------------------------------------------------
67// Service56// Service
68// ---------------------------------------------------------------------------57// ---------------------------------------------------------------------------
@@ -75,16 +64,10 @@ export class DbService extends Context.Tag("@executor/cloud/DbService")< · 6 unmodified lines
75 this,64 this,
76 Effect.gen(function* () {65 Effect.gen(function* () {
77 const connectionString = yield* resolveConnectionString;66 const connectionString = yield* resolveConnectionString;
78 67 const { db } = yield* Effect.acquireRelease(
79 if (connectionString) {68 acquirePostgres(connectionString),
80 const { db } = yield* Effect.acquireRelease(69 releasePostgres,
81 acquirePostgres(connectionString),70 );
82 releasePostgres,
83 );
84 return db;
85 }
86
87 const { db } = yield* Effect.acquireRelease(acquirePglite, releasePglite);
88 return db;71 return db;
89 }),72 }),
90 );73 );

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t