Skip to content

Instantly share code, notes, and snippets.

@devinivy
Last active May 5, 2016 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devinivy/7bbbdab92d96d4c4b1bfd22fb7191668 to your computer and use it in GitHub Desktop.
Save devinivy/7bbbdab92d96d4c4b1bfd22fb7191668 to your computer and use it in GitHub Desktop.
Knex locked connections
'use strict';
const Knex = require('./knex');
const knex = Knex({
dialect: 'postgres',
connection: {
adapter: 'postgresql',
database: 'test',
user: 'postgres'
},
pool: {
min: 2,
max: 2,
// requestTimeout: 1 // Uncomment to make example work
},
acquireConnectionTimeout: 2
});
knex.raw('SELECT 1')
.catch((err) => console.error('Expected1', err))
.then(() => knex.raw('SELECT 1'))
.catch((err) => console.error('Expected2', err))
.then(() => {
return new Promise((res, req) => {
setTimeout(() => {
console.log('Waited– a connection should be available despite previous errors');
// knex.client.pool.requestTimeout = 10000; // Uncomment to make example work
knex.client.config.acquireConnectionTimeout = 10000;
res();
}, 100);
});
})
.then(() => knex.raw('SELECT 1'))
.then(() => knex.raw('SELECT 1'))
.catch((err) => console.error('Unexpected', err, err.stack))
.then(() => process.exit(0));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment