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