(
sql: string,
params: ReadonlyArray<unknown>,
transformRows: (<A extends object>(row: ReadonlyArray<A>) => ReadonlyArray<A>) | undefined
)
| 738 | return this.execute(sql, params, transformRows) |
| 739 | } |
| 740 | executeStream( |
| 741 | sql: string, |
| 742 | params: ReadonlyArray<unknown>, |
| 743 | transformRows: (<A extends object>(row: ReadonlyArray<A>) => ReadonlyArray<A>) | undefined |
| 744 | ) { |
| 745 | // oxlint-disable-next-line @typescript-eslint/no-this-alias |
| 746 | const self = this |
| 747 | return Stream.fromChannel(Channel.fromTransform(Effect.fnUntraced(function*(_, scope) { |
| 748 | const client = yield* Scope.provide(self.reserve, scope) |
| 749 | yield* Scope.addFinalizer(scope, Effect.promise(() => cursor.close())) |
| 750 | const cursor = client.query(new Cursor(sql, params as any)) |
| 751 | // @effect-diagnostics-next-line returnEffectInGen:off |
| 752 | return Effect.callback<Arr.NonEmptyReadonlyArray<any>, SqlError | Cause.Done>((resume) => { |
| 753 | cursor.read(128, (err, rows) => { |
| 754 | if (err) { |
| 755 | resume(Effect.fail(new SqlError({ reason: classifyError(err, "Failed to execute statement", "stream") }))) |
| 756 | } else if (Arr.isArrayNonEmpty(rows)) { |
| 757 | resume(Effect.succeed(transformRows ? transformRows(rows) as any : rows)) |
| 758 | } else { |
| 759 | resume(Cause.done()) |
| 760 | } |
| 761 | }) |
| 762 | }) |
| 763 | }))) |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | const cancelEffects = new WeakMap<Pg.PoolClient, Effect.Effect<void> | undefined>() |
no test coverage detected