MCPcopy Create free account
hub / github.com/Effect-TS/effect / executeStream

Method executeStream

packages/sql/pg/src/PgClient.ts:740–764  ·  view source on GitHub ↗
(
    sql: string,
    params: ReadonlyArray<unknown>,
    transformRows: (<A extends object>(row: ReadonlyArray<A>) => ReadonlyArray<A>) | undefined
  )

Source from the content-addressed store, hash-verified

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
767const cancelEffects = new WeakMap<Pg.PoolClient, Effect.Effect<void> | undefined>()

Callers 1

streamFunction · 0.45

Calls 9

addFinalizerMethod · 0.80
classifyErrorFunction · 0.70
closeMethod · 0.65
readMethod · 0.65
resumeFunction · 0.50
provideMethod · 0.45
failMethod · 0.45
succeedMethod · 0.45
doneMethod · 0.45

Tested by

no test coverage detected