(
options: PgliteClientConfig = {}
)
| 152 | * @since 4.0.0 |
| 153 | */ |
| 154 | export const make = ( |
| 155 | options: PgliteClientConfig = {} |
| 156 | ): Effect.Effect<PgliteClient, SqlError, Scope.Scope | Reactivity.Reactivity> => |
| 157 | Effect.gen(function*() { |
| 158 | const pglite = "liveClient" in options |
| 159 | ? options.liveClient |
| 160 | : yield* Effect.acquireRelease( |
| 161 | Effect.tryPromise({ |
| 162 | try: async () => { |
| 163 | const pg = new PGlite(options) |
| 164 | await pg.waitReady |
| 165 | return pg |
| 166 | }, |
| 167 | catch: (cause) => new SqlError({ reason: classifyError(cause, "PgliteClient: Failed to connect", "connect") }) |
| 168 | }), |
| 169 | (pg) => Effect.promise(() => pg.close()).pipe(Effect.timeoutOption(1000)), |
| 170 | { interruptible: true } |
| 171 | ) |
| 172 | |
| 173 | return yield* fromClient({ ...options, liveClient: pglite }) |
| 174 | }) |
| 175 | |
| 176 | /** |
| 177 | * Builds a `PgliteClient` around an existing PGlite instance, adding SQL client operations, LISTEN/NOTIFY, dump helpers, and serialized access. |
no test coverage detected