MCPcopy Create free account
hub / github.com/porsager/postgres / cursor

Method cursor

cjs/src/query.js:74–111  ·  view source on GitHub ↗
(rows = 1, fn)

Source from the content-addressed store, hash-verified

72 }
73
74 cursor(rows = 1, fn) {
75 this.options.simple = false
76 if (typeof rows === 'function') {
77 fn = rows
78 rows = 1
79 }
80
81 this.cursorRows = rows
82
83 if (typeof fn === 'function')
84 return (this.cursorFn = fn, this)
85
86 let prev
87 return {
88 [Symbol.asyncIterator]: () => ({
89 next: () => {
90 if (this.executed && !this.active)
91 return { done: true }
92
93 prev && prev()
94 const promise = new Promise((resolve, reject) => {
95 this.cursorFn = value => {
96 resolve({ value, done: false })
97 return new Promise(r => prev = r)
98 }
99 this.resolve = () => (this.active = false, resolve({ done: true }))
100 this.reject = x => (this.active = false, reject(x))
101 })
102 this.execute()
103 return promise
104 },
105 return() {
106 prev && prev(CLOSE)
107 return { done: true }
108 }
109 })
110 }
111 }
112
113 describe() {
114 this.options.simple = false

Callers

nothing calls this directly

Calls 1

executeMethod · 0.95

Tested by

no test coverage detected