Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
knex-dynamic-connection
Advanced tools
Adds support for dynamically returning connection config for knex queries
This module is meant to patch knex and add support for defining dynamic connection configuration.
Knex.js doesn't have inbuilt support for read/write connections. One can create two seperate instances of knex for read and write, but that still doesn't completely solve the problem. For example:
const Knex = require('knex')
const writeConfig = {
client: 'pg',
connection: {
}
}
const writer = Knex(writeConfig)
const readConfig = {
client: 'pg',
connection: {
}
}
const reader = Knex(readConfig)
Now, if you want to use multiple servers for read operations, you cannot do that, since knex.js allows only one connection server and will pool connections within that server.
Following is not possible
const readConfig = {
client: 'pg',
connection: [
{
host: ''
},
{
host: ''
}
]
}
With the help of this module, you can make knex create a connection using the dynamic config for every query.
npm i knex-dynamic-connection
const Knex = require('knex')
const { patchKnex } = require('knex-dynamic-connection')
const readConfig = {
client: 'pg',
connection: {},
replicas: [
{
host: '',
},
{
host: '',
}
],
}
const knex = Knex(readConfig)
let roundRobinCounter = 0
patchKnex(knex, (originalConfig) => {
const node = roundRobinCounter++ % originalConfig.replicas.length
return originalConfig.replicas[node]
})
The patchKnex
method overwrites the acquireRawConnection
on all the dialects and make them fetch the config from your callback vs reading it from a static source.
Yes!
acquireRawConnection
from the knex codebase and have just made one line of change to read the config from a different source.select
, insert
, transactions
and schema
methods.mssql
, mysql
, mysql2
and pg
.Knex.js makes use of tarn.js for managing pool resources and everytime pool needs a connection, knexjs calls acquireRawConnection on the dialect in use.
The dialect creates a new connection to the database server, but uses static configuration. I have just added a patch, which will rely on your closure to return the config vs using the same static config all the time.
I am using Knex.js to write the ORM of https://adonisjs.com/ and will keep a close eye on the releases of Knex to make sure that I incorporate any changes made of the underlying code and keep this module upto date. If knex.js team plans to re-write the entire codebase (which is less likely to happen), then I will pitch this change to be a first class citizen.
Yes, there are currently no tests for oracle. It will be great, if you can help set it up using docker
FAQs
Adds support for dynamically returning connection config for knex queries
The npm package knex-dynamic-connection receives a total of 24,348 weekly downloads. As such, knex-dynamic-connection popularity was classified as popular.
We found that knex-dynamic-connection demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.