knex-utils
Advanced tools
Comparing version 4.1.9 to 5.0.0
{ | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1
12
8781
17
95
8
1
+ Addedcolorette@2.0.16(transitive)
+ Addedcommander@7.2.0(transitive)
+ Addeddebug@4.3.2(transitive)
+ Addedgetopts@2.2.5(transitive)
+ Addedknex@0.95.15(transitive)
+ Addedpg-connection-string@2.5.0(transitive)
+ Addedrechoir@0.7.0(transitive)
- Removedknex-tablecleaner@^4.1.0
- Removedvalidation-utils@^6.0.0
- Removedasync@2.6.4(transitive)
- Removedcolorette@2.0.19(transitive)
- Removedcommander@10.0.1(transitive)
- Removeddebug@4.3.4(transitive)
- Removedget-package-type@0.1.0(transitive)
- Removedgetopts@2.3.0(transitive)
- Removedknex@3.1.0(transitive)
- Removedknex-tablecleaner@4.1.0(transitive)
- Removedpg-connection-string@2.6.2(transitive)
- Removedrechoir@0.8.0(transitive)
- Removedvalidation-utils@6.3.0(transitive)
- Removedzoology@1.0.0(transitive)