Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
knex-utils
Advanced tools
Common utilities for knex.js
** Connection init example
const config = require('config');
const { connectionUtils, heartbeatChecker } = require('knex-utils');
const HEARTBEAT_QUERY = heartbeatChecker.HEARTBEAT_QUERIES.POSTGRESQL;
const knexConfig = config.get('db'); //knex-utils directly passes config entity to knex, so see knex documentation for exact format
let _knex;
function getKnexInstance() {
return _knex || _initKnexInstance();
}
function _initKnexInstance() {
_knex = connectionUtils.getKnexInstance(knexConfig, connectionUtils.getRegistry(), logger);
return _knex;
}
/**
*
* @returns {Object} heartbeat check result
*/
function checkHeartBeat() {
return heartbeatChecker.checkHeartbeat(_knex, HEARTBEAT_QUERY);
}
function close() {
if (_knex) {
const promise = _knex.destroy();
_knex = undefined;
connectionUtils.getRegistry().length = 0; //ToDo implement more specific removal of connections from registry
return promise;
}
return Promise.resolve();
}
module.exports = {
getKnexInstance,
checkHeartBeat,
close
};
** Hearbeat usage example
const { heartbeatChecker } = require('knex-utils');
const HEARTBEAT_QUERY = heartbeatChecker.HEARTBEAT_QUERIES.POSTGRESQL;
const knex = require('./db/db.service').getKnexInstance(); //replace with whatever method you use to obtain knex instance
const appPromise = swaggerService.generateSwagger(true) // could be any async startup activity, or you can start the chain with 'db.checkHeartBeat'
.then(async () => {
const dbCheckResult = await heartbeatChecker.checkHeartbeat(knex, HEARTBEAT_QUERY);;
if (dbCheckResult.isOk === false) {
console.error('DB connection error: ', dbCheckResult.error);
throw (dbCheckResult.error);
}
})
.then(async () => {
const app = express();
// <...> complete app initialization omitted
return app;
}
).catch((e) => {
console.error('Error while starting application: ', e);
throw e;
});
function getAppAsync() {
return appPromise;
}
module.exports = {
getAppAsync
};
FAQs
Useful utilities for Knex.js
The npm package knex-utils receives a total of 485 weekly downloads. As such, knex-utils popularity was classified as not popular.
We found that knex-utils demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.