mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
Drop support for EOL versions of node
This commit is contained in:
parent
5cf8f5f8d7
commit
28ca0b10e2
11
.travis.yml
11
.travis.yml
@ -17,11 +17,6 @@ addons:
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- node_js: lts/carbon
|
||||
addons:
|
||||
postgresql: "9.5"
|
||||
dist: precise
|
||||
|
||||
# different PostgreSQL versions on Node LTS
|
||||
- node_js: lts/erbium
|
||||
addons:
|
||||
@ -35,9 +30,3 @@ matrix:
|
||||
- node_js: lts/erbium
|
||||
addons:
|
||||
postgresql: "9.6"
|
||||
|
||||
# PostgreSQL 9.2 only works on precise
|
||||
- node_js: lts/carbon
|
||||
addons:
|
||||
postgresql: "9.2"
|
||||
dist: precise
|
||||
|
||||
@ -34,6 +34,6 @@
|
||||
"pg-cursor": "^1.3.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"pg": ">5.0"
|
||||
"pg": ">8.0"
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,112 +0,0 @@
|
||||
const QueryStream = require('../')
|
||||
const pg = require('pg')
|
||||
const assert = require('assert')
|
||||
|
||||
const queryText = 'SELECT * FROM generate_series(0, 200) num'
|
||||
describe('Async iterator', () => {
|
||||
it('works', async () => {
|
||||
const stream = new QueryStream(queryText, [])
|
||||
const client = new pg.Client()
|
||||
await client.connect()
|
||||
const query = client.query(stream)
|
||||
const rows = []
|
||||
for await (const row of query) {
|
||||
rows.push(row)
|
||||
}
|
||||
assert.equal(rows.length, 201)
|
||||
await client.end()
|
||||
})
|
||||
|
||||
it('can async iterate and then do a query afterwards', async () => {
|
||||
const stream = new QueryStream(queryText, [])
|
||||
const client = new pg.Client()
|
||||
await client.connect()
|
||||
const query = client.query(stream)
|
||||
const iteratorRows = []
|
||||
for await (const row of query) {
|
||||
iteratorRows.push(row)
|
||||
}
|
||||
assert.equal(iteratorRows.length, 201)
|
||||
const { rows } = await client.query('SELECT NOW()')
|
||||
assert.equal(rows.length, 1)
|
||||
await client.end()
|
||||
})
|
||||
|
||||
it('can async iterate multiple times with a pool', async () => {
|
||||
const pool = new pg.Pool({ max: 1 })
|
||||
|
||||
const allRows = []
|
||||
const run = async () => {
|
||||
// get the client
|
||||
const client = await pool.connect()
|
||||
// stream some rows
|
||||
const stream = new QueryStream(queryText, [])
|
||||
const iteratorRows = []
|
||||
client.query(stream)
|
||||
for await (const row of stream) {
|
||||
iteratorRows.push(row)
|
||||
allRows.push(row)
|
||||
}
|
||||
assert.equal(iteratorRows.length, 201)
|
||||
client.release()
|
||||
}
|
||||
await Promise.all([run(), run(), run()])
|
||||
assert.equal(allRows.length, 603)
|
||||
await pool.end()
|
||||
})
|
||||
|
||||
it('can break out of iteration early', async () => {
|
||||
const pool = new pg.Pool({ max: 1 })
|
||||
const client = await pool.connect()
|
||||
const rows = []
|
||||
for await (const row of client.query(new QueryStream(queryText, [], { batchSize: 1 }))) {
|
||||
rows.push(row)
|
||||
break;
|
||||
}
|
||||
for await (const row of client.query(new QueryStream(queryText, []))) {
|
||||
rows.push(row)
|
||||
break;
|
||||
}
|
||||
for await (const row of client.query(new QueryStream(queryText, []))) {
|
||||
rows.push(row)
|
||||
break;
|
||||
}
|
||||
assert.strictEqual(rows.length, 3)
|
||||
client.release()
|
||||
await pool.end()
|
||||
})
|
||||
|
||||
it('only returns rows on first iteration', async () => {
|
||||
const pool = new pg.Pool({ max: 1 })
|
||||
const client = await pool.connect()
|
||||
const rows = []
|
||||
const stream = client.query(new QueryStream(queryText, []))
|
||||
for await (const row of stream) {
|
||||
rows.push(row)
|
||||
break;
|
||||
}
|
||||
for await (const row of stream) {
|
||||
rows.push(row)
|
||||
}
|
||||
for await (const row of stream) {
|
||||
rows.push(row)
|
||||
}
|
||||
assert.strictEqual(rows.length, 1)
|
||||
client.release()
|
||||
await pool.end()
|
||||
})
|
||||
|
||||
it('can read with delays', async () => {
|
||||
const pool = new pg.Pool({ max: 1 })
|
||||
const client = await pool.connect()
|
||||
const rows = []
|
||||
const stream = client.query(new QueryStream(queryText, [], { batchSize: 1 }))
|
||||
for await (const row of stream) {
|
||||
rows.push(row)
|
||||
await new Promise((resolve) => setTimeout(resolve, 1))
|
||||
}
|
||||
assert.strictEqual(rows.length, 201)
|
||||
client.release()
|
||||
await pool.end()
|
||||
})
|
||||
})
|
||||
@ -1,4 +1,112 @@
|
||||
// only newer versions of node support async iterator
|
||||
if (!process.version.startsWith('v8')) {
|
||||
require('./async-iterator.es6')
|
||||
}
|
||||
const QueryStream = require('../')
|
||||
const pg = require('pg')
|
||||
const assert = require('assert')
|
||||
|
||||
const queryText = 'SELECT * FROM generate_series(0, 200) num'
|
||||
describe('Async iterator', () => {
|
||||
it('works', async () => {
|
||||
const stream = new QueryStream(queryText, [])
|
||||
const client = new pg.Client()
|
||||
await client.connect()
|
||||
const query = client.query(stream)
|
||||
const rows = []
|
||||
for await (const row of query) {
|
||||
rows.push(row)
|
||||
}
|
||||
assert.equal(rows.length, 201)
|
||||
await client.end()
|
||||
})
|
||||
|
||||
it('can async iterate and then do a query afterwards', async () => {
|
||||
const stream = new QueryStream(queryText, [])
|
||||
const client = new pg.Client()
|
||||
await client.connect()
|
||||
const query = client.query(stream)
|
||||
const iteratorRows = []
|
||||
for await (const row of query) {
|
||||
iteratorRows.push(row)
|
||||
}
|
||||
assert.equal(iteratorRows.length, 201)
|
||||
const { rows } = await client.query('SELECT NOW()')
|
||||
assert.equal(rows.length, 1)
|
||||
await client.end()
|
||||
})
|
||||
|
||||
it('can async iterate multiple times with a pool', async () => {
|
||||
const pool = new pg.Pool({ max: 1 })
|
||||
|
||||
const allRows = []
|
||||
const run = async () => {
|
||||
// get the client
|
||||
const client = await pool.connect()
|
||||
// stream some rows
|
||||
const stream = new QueryStream(queryText, [])
|
||||
const iteratorRows = []
|
||||
client.query(stream)
|
||||
for await (const row of stream) {
|
||||
iteratorRows.push(row)
|
||||
allRows.push(row)
|
||||
}
|
||||
assert.equal(iteratorRows.length, 201)
|
||||
client.release()
|
||||
}
|
||||
await Promise.all([run(), run(), run()])
|
||||
assert.equal(allRows.length, 603)
|
||||
await pool.end()
|
||||
})
|
||||
|
||||
it('can break out of iteration early', async () => {
|
||||
const pool = new pg.Pool({ max: 1 })
|
||||
const client = await pool.connect()
|
||||
const rows = []
|
||||
for await (const row of client.query(new QueryStream(queryText, [], { batchSize: 1 }))) {
|
||||
rows.push(row)
|
||||
break;
|
||||
}
|
||||
for await (const row of client.query(new QueryStream(queryText, []))) {
|
||||
rows.push(row)
|
||||
break;
|
||||
}
|
||||
for await (const row of client.query(new QueryStream(queryText, []))) {
|
||||
rows.push(row)
|
||||
break;
|
||||
}
|
||||
assert.strictEqual(rows.length, 3)
|
||||
client.release()
|
||||
await pool.end()
|
||||
})
|
||||
|
||||
it('only returns rows on first iteration', async () => {
|
||||
const pool = new pg.Pool({ max: 1 })
|
||||
const client = await pool.connect()
|
||||
const rows = []
|
||||
const stream = client.query(new QueryStream(queryText, []))
|
||||
for await (const row of stream) {
|
||||
rows.push(row)
|
||||
break;
|
||||
}
|
||||
for await (const row of stream) {
|
||||
rows.push(row)
|
||||
}
|
||||
for await (const row of stream) {
|
||||
rows.push(row)
|
||||
}
|
||||
assert.strictEqual(rows.length, 1)
|
||||
client.release()
|
||||
await pool.end()
|
||||
})
|
||||
|
||||
it('can read with delays', async () => {
|
||||
const pool = new pg.Pool({ max: 1 })
|
||||
const client = await pool.connect()
|
||||
const rows = []
|
||||
const stream = client.query(new QueryStream(queryText, [], { batchSize: 1 }))
|
||||
for await (const row of stream) {
|
||||
rows.push(row)
|
||||
await new Promise((resolve) => setTimeout(resolve, 1))
|
||||
}
|
||||
assert.strictEqual(rows.length, 201)
|
||||
client.release()
|
||||
await pool.end()
|
||||
})
|
||||
})
|
||||
|
||||
@ -62,6 +62,4 @@ test-pool:
|
||||
|
||||
lint:
|
||||
@echo "***Starting lint***"
|
||||
node -e "process.exit(Number(process.versions.node.split('.')[0]) < 8 ? 0 : 1)" \
|
||||
&& echo "***Skipping lint (node version too old)***" \
|
||||
|| node_modules/.bin/eslint lib
|
||||
node_modules/.bin/eslint lib
|
||||
|
||||
@ -51,6 +51,6 @@
|
||||
],
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 4.5.0"
|
||||
"node": ">= 10.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user