(
sql: string,
params: ReadonlyArray<unknown> = []
)
| 164 | yield* Effect.addFinalizer(() => Effect.sync(() => db.close())) |
| 165 | |
| 166 | const run = ( |
| 167 | sql: string, |
| 168 | params: ReadonlyArray<unknown> = [] |
| 169 | ) => |
| 170 | Effect.withFiber<Array<any>, SqlError>((fiber) => { |
| 171 | if (fiber.getRef(AsyncQuery)) { |
| 172 | return Effect.map( |
| 173 | Effect.tryPromise({ |
| 174 | try: () => db.execute(sql, params as Array<any>), |
| 175 | catch: (cause) => |
| 176 | new SqlError({ reason: classifyError(cause, "Failed to execute statement (async)", "execute") }) |
| 177 | }), |
| 178 | (result) => result.rows |
| 179 | ) |
| 180 | } |
| 181 | return Effect.try({ |
| 182 | try: () => db.executeSync(sql, params as Array<any>).rows, |
| 183 | catch: (cause) => new SqlError({ reason: classifyError(cause, "Failed to execute statement", "execute") }) |
| 184 | }) |
| 185 | }) |
| 186 | |
| 187 | const runValues = ( |
| 188 | sql: string, |
no test coverage detected