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

Function runQuery

packages/sql/pg/src/PgConnection.ts:1958–1990  ·  view source on GitHub ↗
(
  conn: PgConnectionImpl,
  plan: Plan,
  output: Output
)

Source from the content-addressed store, hash-verified

1956
1957/** One cycle on a connection that carries a single statement at a time. */
1958const runQuery = (
1959 conn: PgConnectionImpl,
1960 plan: Plan,
1961 output: Output
1962): Effect.Effect<QueryOutput, SqlError> =>
1963 Effect.callback<QueryOutput, SqlError>((resume) => {
1964 if (conn.deadWith !== undefined) {
1965 resume(Effect.fail(conn.deadWith))
1966 return
1967 }
1968 const machine = new QueryMachine(conn, plan, output, (effect) => {
1969 conn.consumer = undefined
1970 resume(effect)
1971 })
1972 conn.consumer = machine
1973 // A reused statement has no `RowDescription` coming, so its reader has to
1974 // be in place before the rows are.
1975 conn.session.parser.readField = machine.readField
1976 try {
1977 conn.session.socket.write(plan.frame)
1978 } catch (cause) {
1979 conn.fatal(connectionQueryError(cause, "PgConnection: Failed to write query"))
1980 }
1981
1982 return Effect.suspend(() => {
1983 if (machine.isDone()) return Effect.void
1984 return drainAborted(conn, "Query cancellation timed out", (onDrained) =>
1985 machine.abort(() => {
1986 conn.consumer = undefined
1987 onDrained()
1988 }))
1989 })
1990 })
1991
1992// Preserve leading U+FEFF as data rather than stripping it as a BOM.
1993const textDecoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true })

Callers 1

PgConnectionImplClass · 0.85

Calls 8

isDoneMethod · 0.95
abortMethod · 0.95
connectionQueryErrorFunction · 0.85
drainAbortedFunction · 0.85
fatalMethod · 0.80
failMethod · 0.65
writeMethod · 0.65
resumeFunction · 0.50

Tested by

no test coverage detected