( conn: PgConnectionImpl, plan: Plan, output: Output )
| 1956 | |
| 1957 | /** One cycle on a connection that carries a single statement at a time. */ |
| 1958 | const 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. |
| 1993 | const textDecoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }) |
no test coverage detected