GeezerVison is showing github.com — refactor(relay): acquire unlink services from context · pingdotgg/t3code@7800b33
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: infra/relay/src/db.ts +18Lines changed: 18 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -7,6 +7,7 @@ import * as RemovalPolicy from "alchemy/RemovalPolicy"; |
7 | 7 | import type { EffectPgDatabase } from "drizzle-orm/effect-postgres"; |
8 | 8 | import * as Context from "effect/Context"; |
9 | 9 | import * as Effect from "effect/Effect"; |
| 10 | +import * as Layer from "effect/Layer"; |
10 | 11 |
|
11 | 12 | import { relayDatabaseMode } from "./dbConfig.ts"; |
12 | 13 |
|
@@ -17,6 +18,23 @@ export class RelayDb extends Context.Service< |
17 | 18 | } |
18 | 19 | >()("t3code-relay/db/RelayDb") {} |
19 | 20 |
|
| 21 | +export class RelayTransactions extends Context.Service< |
| 22 | + RelayTransactions, |
| 23 | + { |
| 24 | + readonly withTransaction: RelayDb["Service"]["$client"]["withTransaction"]; |
| 25 | + } |
| 26 | +>()("t3code-relay/db/RelayTransactions") { |
| 27 | + static readonly layer = Layer.effect( |
| 28 | + RelayTransactions, |
| 29 | + Effect.gen(function* () { |
| 30 | + const db = yield* RelayDb; |
| 31 | + return RelayTransactions.of({ |
| 32 | + withTransaction: db.$client.withTransaction, |
| 33 | + }); |
| 34 | + }), |
| 35 | + ); |
| 36 | +} |
| 37 | + |
20 | 38 | export const PlanetscaleDatabase = Effect.gen(function* () { |
21 | 39 | const { stage } = yield* Alchemy.Stack; |
22 | 40 | const schema = yield* Drizzle.Schema("RelaySchema", { |
|