(message: PgProtocol.BackendMessage<unknown>)
| 1801 | } |
| 1802 | |
| 1803 | onMessage(message: PgProtocol.BackendMessage<unknown>): void { |
| 1804 | if (this.aborted) { |
| 1805 | if (message._tag === "ReadyForQuery") { |
| 1806 | this.done = true |
| 1807 | this.drainDone?.() |
| 1808 | } |
| 1809 | return |
| 1810 | } |
| 1811 | if (this.phase === "drain") { |
| 1812 | if (message._tag === "ReadyForQuery") return this.complete(Effect.fail(this.failure!)) |
| 1813 | if (skippedWhileDraining(message) || (this.remaining > 1 && opensStatement(message))) return |
| 1814 | return this.failDesync(`Unexpected ${message._tag} after a row failed to decode`) |
| 1815 | } |
| 1816 | if (this.phase === "error") { |
| 1817 | if (message._tag === "ReadyForQuery") { |
| 1818 | // Retrying in an aborted transaction would mask the original error with 25P02. |
| 1819 | if (this.plan.stale && !this.plan.parses && message.status === "E") { |
| 1820 | this.conn.prepared?.evict(this.plan.prepared!) |
| 1821 | this.plan.stale = false |
| 1822 | } |
| 1823 | return this.complete(Effect.fail(this.failure!)) |
| 1824 | } |
| 1825 | return this.failDesync(`Unexpected ${message._tag} after ErrorResponse`) |
| 1826 | } |
| 1827 | switch (message._tag) { |
| 1828 | case "CloseComplete": |
| 1829 | if (this.phase !== "close") return this.failDesync(`Unexpected CloseComplete during ${this.phase}`) |
| 1830 | if (--this.closes === 0) this.phase = this.plan.parses ? "parse" : "bind" |
| 1831 | return |
| 1832 | case "ParseComplete": |
| 1833 | if (this.phase !== "parse") return this.failDesync(`Unexpected ParseComplete during ${this.phase}`) |
| 1834 | this.phase = "bind" |
| 1835 | return |
| 1836 | case "BindComplete": |
| 1837 | if (this.phase !== "bind") return this.failDesync(`Unexpected BindComplete during ${this.phase}`) |
| 1838 | this.phase = this.plan.describes ? "describe" : "rows" |
| 1839 | return |
| 1840 | case "RowDescription": { |
| 1841 | if (this.phase !== "describe") return this.failDesync(`Unexpected RowDescription during ${this.phase}`) |
| 1842 | const description = describe(message.fields, this.conn.registry, this.output === "text") |
| 1843 | if (EffectResult.isFailure(description)) { |
| 1844 | return this.conn.fatal(queryError(description.failure, "PgConnection: Failed to decode row")) |
| 1845 | } |
| 1846 | this.fieldCount = message.fields.length |
| 1847 | this.resultFields = description.success.resultFields |
| 1848 | this.rowBuilder = description.success.rowBuilder |
| 1849 | // `pushEach` hands this description over before it reads the rows |
| 1850 | // behind it, including rows that arrived in the same chunk. |
| 1851 | this.conn.session.parser.readField = description.success.readField |
| 1852 | const prepared = this.plan.prepared |
| 1853 | if (prepared !== undefined) { |
| 1854 | prepared.description = description.success |
| 1855 | prepared.ready = true |
| 1856 | } |
| 1857 | this.phase = "rows" |
| 1858 | return |
| 1859 | } |
| 1860 | case "NoData": { |
no test coverage detected