| ... | ... | @@ -16,15 +16,14 @@ const defaultSqliteClientLoaders = { |
| 16 | 16 | node: () => import("../NodeSqliteClient.ts"), |
| 17 | 17 | } satisfies Record<string, () => Promise<Loader>>; |
| 18 | 18 | |
| 19 | | const makeRuntimeSqliteLayer = ( |
| 19 | const makeRuntimeSqliteLayer = Effect.fn("makeRuntimeSqliteLayer")(function* ( |
| 20 | 20 | config: RuntimeSqliteLayerConfig, |
| 21 | | ): Layer.Layer<SqlClient.SqlClient> => |
| 22 | | Effect.gen(function* () { |
| 23 | | const runtime = process.versions.bun !== undefined ? "bun" : "node"; |
| 24 | | const loader = defaultSqliteClientLoaders[runtime]; |
| 25 | | const clientModule = yield* Effect.promise<Loader>(loader); |
| 26 | | return clientModule.layer(config); |
| 27 | | }).pipe(Layer.unwrap); |
| 21 | ) { |
| 22 | const runtime = process.versions.bun !== undefined ? "bun" : "node"; |
| 23 | const loader = defaultSqliteClientLoaders[runtime]; |
| 24 | const clientModule = yield* Effect.promise<Loader>(loader); |
| 25 | return clientModule.layer(config); |
| 26 | }, Layer.unwrap); |
| 28 | 27 | |
| 29 | 28 | const setup = Layer.effectDiscard( |
| 30 | 29 | Effect.gen(function* () { |
| ... | ... | @@ -35,14 +34,15 @@ const setup = Layer.effectDiscard( |
| 35 | 34 | }), |
| 36 | 35 | ); |
| 37 | 36 | |
| 38 | | export const makeSqlitePersistenceLive = (dbPath: string) => |
| 39 | | Effect.gen(function* () { |
| 40 | | const fs = yield* FileSystem.FileSystem; |
| 41 | | const path = yield* Path.Path; |
| 42 | | yield* fs.makeDirectory(path.dirname(dbPath), { recursive: true }); |
| 37 | export const makeSqlitePersistenceLive = Effect.fn("makeSqlitePersistenceLive")(function* ( |
| 38 | dbPath: string, |
| 39 | ) { |
| 40 | const fs = yield* FileSystem.FileSystem; |
| 41 | const path = yield* Path.Path; |
| 42 | yield* fs.makeDirectory(path.dirname(dbPath), { recursive: true }); |
| 43 | 43 | |
| 44 | | return Layer.provideMerge(setup, makeRuntimeSqliteLayer({ filename: dbPath })); |
| 45 | | }).pipe(Layer.unwrap); |
| 44 | return Layer.provideMerge(setup, makeRuntimeSqliteLayer({ filename: dbPath })); |
| 45 | }, Layer.unwrap); |
| 46 | 46 | |
| 47 | 47 | export const SqlitePersistenceMemory = Layer.provideMerge( |
| 48 | 48 | setup, |