dd-trace-js
dd-trace-js copied to clipboard
pg plugin: support cursors
this adds support for cursor queries, where the query has a cursor object (where the sql text is), and the result is a readable stream. see: https://node-postgres.com/api/cursor
(coming from #860)
@rochdev I'm trying to figure out how to write a test for this, one first thing that I noticed is that to use a cursor you need an extra package, pg-cursor (besides pg), eg:
const { Pool } = require('pg')
const Cursor = require('pg-cursor')
const pool = new Pool()
const client = await pool.connect()
const cursor = client.query(new Cursor('select * from generate_series(0, 5)'))
cursor.read(100, (err, rows) => {
if (err) {
throw err
}
assert(rows.length == 6)
cursor.read(100, (err, rows) => {
assert(rows.length == 0)
})
})
but I don't think this are supposed to be installed here, can you help me understand how to mock this dependency?
You can add dependencies for a test in a new entry under pg in externals.json. Then to use it you would have to require it from the versions folder as can be seen in this plugin.
So in your test the test wrapper would look like this:
withVersions(plugin, 'pg-cursor', cursorVersion => {
let Cursor
beforeEach(() => {
Cursor = require(`../../../versions/pg-cursor@${cursorVersion}`).get()
})
If you use a fixed version instead of a range the wrapper will only run once for that version.
Hey @benjamine, we're looking at closing old PRs out. This one of course has some merge conflicts and an open query by rochdev. Is it something you'd be interested in patching up or is it safe to close?
Closing this as stale.