(
sql: string,
params: ReadonlyArray<unknown> = []
)
| 107 | yield* Effect.addFinalizer(() => Effect.sync(() => db.close())) |
| 108 | |
| 109 | const run = ( |
| 110 | sql: string, |
| 111 | params: ReadonlyArray<unknown> = [] |
| 112 | ) => |
| 113 | Effect.withFiberRuntime<Array<any>, SqlError>((fiber) => { |
| 114 | if (fiber.getFiberRef(asyncQuery)) { |
| 115 | return Effect.map( |
| 116 | Effect.tryPromise({ |
| 117 | try: () => db.executeAsync(sql, params as Array<any>), |
| 118 | catch: (cause) => new SqlError({ cause, message: "Failed to execute statement (async)" }) |
| 119 | }), |
| 120 | (result) => result.rows?._array ?? [] |
| 121 | ) |
| 122 | } |
| 123 | return Effect.try({ |
| 124 | try: () => db.execute(sql, params as Array<any>).rows?._array ?? [], |
| 125 | catch: (cause) => new SqlError({ cause, message: "Failed to execute statement" }) |
| 126 | }) |
| 127 | }) |
| 128 | |
| 129 | return identity<SqliteConnection>({ |
| 130 | execute(sql, params, transformRows) { |
no test coverage detected