mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
I didn't do much to "modernize" the pg-native codebase other than running it through the standard eslint --fix that is applied to the rest of the code. There's some easy opportunities there to update it to es6 and so on...it still uses some pretty antiquated coding styles in places. This PR re-introduces the native tests on node v20, and updates test matrix to drop unsupported versions of node & add in node v22.
53 lines
994 B
JavaScript
53 lines
994 B
JavaScript
var pg = require('pg').native
|
|
var Native = require('../')
|
|
|
|
var warmup = function (fn, cb) {
|
|
var count = 0
|
|
var max = 10
|
|
var run = function (err) {
|
|
if (err) return cb(err)
|
|
|
|
if (max >= count++) {
|
|
return fn(run)
|
|
}
|
|
|
|
cb()
|
|
}
|
|
run()
|
|
}
|
|
|
|
var native = Native()
|
|
native.connectSync()
|
|
|
|
var queryText = 'SELECT generate_series(0, 1000)'
|
|
var client = new pg.Client()
|
|
client.connect(function () {
|
|
var pure = function (cb) {
|
|
client.query(queryText, function (err) {
|
|
if (err) throw err
|
|
cb(err)
|
|
})
|
|
}
|
|
var nativeQuery = function (cb) {
|
|
native.query(queryText, function (err) {
|
|
if (err) throw err
|
|
cb(err)
|
|
})
|
|
}
|
|
|
|
var run = function () {
|
|
var start = Date.now()
|
|
warmup(pure, function () {
|
|
console.log('pure done', Date.now() - start)
|
|
start = Date.now()
|
|
warmup(nativeQuery, function () {
|
|
console.log('native done', Date.now() - start)
|
|
})
|
|
})
|
|
}
|
|
|
|
setInterval(function () {
|
|
run()
|
|
}, 500)
|
|
})
|