|
90 | 90 | ---@field escapeBytea fun(self: PGconn, str: string): string
|
91 | 91 | ---@field unescapeBytea fun(self: PGconn, str: string): string
|
92 | 92 | ---@field setNotifyCallback fun(self: PGconn, callback: fun(channel: string, payload: string, backendPID: number))
|
| 93 | +---@field getNotifyCallback fun(self: PGconn): fun(channel: string, payload: string, backendPID: number) |
| 94 | +---@field setArrayResult fun(self: PGconn, enabled: boolean) |
| 95 | +---@field getArrayResult fun(self: PGconn): boolean |
93 | 96 |
|
94 | 97 | ---@class PGResult
|
95 | 98 | ---@field fields { name: string, type: number }[] list of fields in the result
|
|
161 | 164 | ---@field url string **readonly** connection url
|
162 | 165 | ---@field connecting boolean **readonly** is client connecting to the database
|
163 | 166 | ---@field closed boolean **readonly** is client closed (to change it to true use `:close()`)
|
| 167 | +---@field array_result boolean option to receive PGResult row fields as array instead of table (default: false) |
164 | 168 | ---@field private conn PGconn native connection object (do not use it directly, otherwise be careful not to store it anywhere else, otherwise closing connection will be impossible)
|
165 | 169 | ---@field private queries { push: fun(self, q: PGQuery), prepend: fun(self, q: PGQuery), pop: (fun(self): PGQuery), size: fun(self): number } list of queries
|
166 | 170 | ---@field package acquired boolean
|
|
275 | 279 | ---@private
|
276 | 280 | ---@param query PGQuery
|
277 | 281 | function Client:runQuery(query)
|
| 282 | + local array_result = self.array_result |
| 283 | + if array_result then |
| 284 | + self.conn:setArrayResult(true) |
| 285 | + end |
| 286 | + |
278 | 287 | local function callback(ok, result, errdata)
|
| 288 | + if array_result and not self.conn:querying() then |
| 289 | + -- final query, reset array result |
| 290 | + self.conn:setArrayResult(false) |
| 291 | + end |
| 292 | + |
279 | 293 | xpcall(query.callback, ErrorNoHaltWithStack, ok, result, errdata)
|
280 | 294 | self:processQueue()
|
281 | 295 | end
|
@@ -934,6 +948,7 @@ function Pool:describePortal(name, callback)
|
934 | 948 | end)
|
935 | 949 | end
|
936 | 950 |
|
| 951 | +---@async |
937 | 952 | local function transactionThread(client, callback)
|
938 | 953 | xpcall(function()
|
939 | 954 | local ctx = TransactionContext.new(client)
|
|
0 commit comments