使用pg-cursor查询数据

问题描述 投票:0回答:1

我有以下代码来从 CloudFlare 工作线程中使用 PG 游标的查询读取前 10 行:

const client = new Client(`<DATABASE URL>`)
await client.connect()
const cursor = client.query(new Cursor(queryString))
let rows = await cursor.read(10)
cursor.close(() => client.release())

但是,这将返回以下内容:

ReferenceError: setImmediate is not defined
    at Cursor2._sendRows (file:///Users/neil/code/console-query-runner/node_modules/pg-cursor/index.js:120:5)
    at Cursor2.handlePortalSuspended (file:///Users/neil/code/console-query-runner/node_modules/pg-cursor/index.js:140:10)
    at Client2._handlePortalSuspended (file:///Users/neil/code/console-query-runner/node_modules/pg/lib/client.js:372:22)
    at emitOne (node-modules-polyfills:events:84:13)
    at Connection.emit2 [as emit] (node-modules-polyfills:events:171:7)
...

通过一些挖掘,似乎

setImmediate
是一些内置的 Node-ism,默认情况下 CF Workers 中不可用。我该如何解决这个问题?

javascript node-postgres pg-cursor
1个回答
0
投票

在这种情况下你似乎需要垫片

setImmediate

$ npm i setimmediate

然后

require('setimmediate')
尽早在您的应用程序中。

© www.soinside.com 2019 - 2024. All rights reserved.