Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
FROM ${table} WHERE tick_time > ${start_time} AND tick_time < ${end_time};`;
client.query(query, [], (err, res)=>{
done();
if(err) {
r(console.error('error running query', err));
} else {
f(res.rows);
}
});
});
});
}
};
var pool = new pg.Pool(pool_conf).on('error', function (err, client) {
console.error('idle client error', err.message, err.stack);
});
var Db = {
pool: pool,
accessors: accessors,
};
module.exports = Db;
function setConnectionString (s) {
var c = parseConnection(s);
pool = new pg.Pool(c);
pool.on('error', function (err, client) {
console.error('idle client error', err.message, err.stack);
});
}
export default function postgresql() {
const configs = {
user: config.get('postgresql.user'),
database: config.get('postgresql.database'),
password: config.get('postgresql.password'),
host: config.get('postgresql.host'),
port: 5432,
max: poolSize,
idleTimeoutMillis: 30000
};
const pool = new native.Pool(configs);
pool.on('error', function (err) {
log('error', `idle client error ${err.message} ${err.stack}`);
});
async function isDbAlive() {
const testQuery = 'SELECT 1';
const metric = timingMetric(DATABASE, {tags: {sqlOperation: 'isDbAlive'}});
try {
const result = await pool.query(testQuery, []);
return Boolean(result.rowCount && result.rowCount === 1);
} catch (e) {
return false;
} finally {
metrics.write(metric);
}