Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

knex-utils

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

knex-utils - npm Package Compare versions

Comparing version 4.1.9 to 5.0.0

dist/index.d.ts

96

package.json
{
"name": "knex-utils",
"version": "4.1.9",
"description": "knex.js utils",
"main": "src/index.js",
"scripts": {
"coveralls": "nyc report --reporter=lcov",
"test": "mocha --opts \"./mocha.opts\" test/**/*.spec.js",
"test:coverage": "nyc npm test",
"lint": "eslint .",
"prettier": "prettier --write \"{lib,test}/**/*.{js,ts}\" index.js"
},
"version": "5.0.0",
"license": "MIT",

@@ -18,60 +9,59 @@ "maintainers": [

"email": "kibertoad@gmail.com"
},
{
"name": "Nikita Gedgaudas",
"email": "gedgaudasnikita@gmail.com"
}
],
"repository": {
"type": "git",
"url": "git://github.com/kibertoad/knex-utils.git"
"description": "Useful utilities for Knex.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"db:start": "docker-compose -f scripts/docker-compose.yml up --build -d mysql postgres mssql && docker-compose -f scripts/docker-compose.yml up waitmssql waitmysql waitpostgres",
"db:stop": "docker-compose -f scripts/docker-compose.yml down",
"test": "jest --config=jest.config.json --runInBand",
"test:coverage": "jest --config=jest.config.json --coverage --runInBand",
"test:ci": "npm run lint && npm run test:coverage",
"lint": "eslint --format codeframe \"lib/**/*.ts\" \"test/**/*.ts\"",
"prettier": "prettier --write \"{lib,test}/**/*.{js,ts}\" index.ts",
"prepublishOnly": "npm run build"
},
"homepage": "https://github.com/kibertoad/knex-utils",
"dependencies": {
"knex-tablecleaner": "^4.1.0",
"validation-utils": "^6.0.0"
},
"peerDependencies": {
"knex": " >= 0.14.5"
"knex": "^0.95.4"
},
"devDependencies": {
"chai": "^4.2.0",
"eslint": "^7.16.0",
"eslint-config-prettier": "^7.1.0",
"eslint-plugin-prettier": "^3.3.0",
"knex": "0.19.5",
"mocha": "^6.2.3",
"nyc": "^14.1.1",
"prettier": "^2.2.1",
"sinon": "^7.5.0"
"@types/jest": "^26.0.23",
"@types/node": "^15.12.4",
"@typescript-eslint/eslint-plugin": "^4.28.0",
"@typescript-eslint/parser": "^4.28.0",
"eslint": "^7.29.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"jest": "^27.0.5",
"knex": "^0.95.6",
"mysql": "^2.18.1",
"mysql2": "^2.2.5",
"pg": "^8.6.0",
"prettier": "^2.3.1",
"sqlite3": "^5.0.2",
"tedious": "^11.0.9",
"ts-jest": "^27.0.3",
"typescript": "4.3.4"
},
"nyc": {
"description": "test coverage",
"include": [
"lib/**"
],
"cache": true,
"all": true,
"check-coverage": true,
"lines": 66,
"statements": 66,
"functions": 60,
"branches": 45
"engines": {
"node": ">=10"
},
"homepage": "http://github.com/knex/knex-utils",
"repository": {
"type": "git",
"url": "git://github.com/knex/knex-utils.git"
},
"keywords": [
"knex",
"utils",
"heartbeat",
"clean",
"where",
"query",
"build",
"builder"
"utilities",
"heartbeat"
],
"files": [
"lib/*",
"index.js",
"README.md",
"LICENSE",
"README.md"
"dist/*"
]
}

@@ -1,85 +0,7 @@

# Knex Utils
# knex-utils
Common utilities for knex.js
[![npm version](http://img.shields.io/npm/v/knex.svg)](https://npmjs.org/package/knex)
![](https://github.com/knex/knex-utils/workflows/CI/badge.svg)
[![Coverage Status](https://coveralls.io/repos/knex/knex-utils/badge.svg?branch=master)](https://coveralls.io/r/knex/knex-utils?branch=master)
[![npm version](http://img.shields.io/npm/v/knex-utils.svg)](https://npmjs.org/package/knex-utils)
[![npm downloads](https://img.shields.io/npm/dm/knex-utils.svg)](https://npmjs.org/package/knex-utils)
![](https://github.com/kibertoad/knex-utils/workflows/unit-tests/badge.svg)
## Connection init example
```js
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
```js
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
};
```
Useful utilities for Knex.js

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc