mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
* feat(): start converting pg-query stream * feat(): solution project, initial version of typescript-pg-query stream * chore(): mocha with typescript * fix(): eslint ignore query stream dist * refactor(pg-query-stream): convert test to ts * chore(): fixed type errors * chore(): fix helper usage * chore(): use ts-node compatibile with node v8 * fix(): addd es extension * chore(): remove emitClose and added compilation for async iterators * chore(): condition for asyc iteration test * chore(): rename class to match ts-defs * chore(): tests to import from src instead of dist * chore(): remove prettier from peer deps: * chore(): update lock file
34 lines
950 B
TypeScript
34 lines
950 B
TypeScript
import pg from 'pg'
|
|
import QueryStream from '../src'
|
|
|
|
describe('end semantics race condition', function () {
|
|
before(function (done) {
|
|
const client = new pg.Client()
|
|
client.connect()
|
|
client.on('drain', client.end.bind(client))
|
|
client.on('end', done)
|
|
client.query('create table IF NOT EXISTS p(id serial primary key)')
|
|
client.query('create table IF NOT EXISTS c(id int primary key references p)')
|
|
})
|
|
it('works', function (done) {
|
|
const client1 = new pg.Client()
|
|
client1.connect()
|
|
const client2 = new pg.Client()
|
|
client2.connect()
|
|
|
|
const qr = new QueryStream('INSERT INTO p DEFAULT VALUES RETURNING id')
|
|
client1.query(qr)
|
|
let id = null
|
|
qr.on('data', function (row) {
|
|
id = row.id
|
|
})
|
|
qr.on('end', function () {
|
|
client2.query('INSERT INTO c(id) VALUES ($1)', [id], function (err, rows) {
|
|
client1.end()
|
|
client2.end()
|
|
done(err)
|
|
})
|
|
})
|
|
})
|
|
})
|