
Security News
Risky Biz Podcast: Making Reachability Analysis Work in Real-World Codebases
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
@loke/db-kit
Advanced tools
Wrapper around knex to provide some sugar such as metrics and slow query logging
A lib for use with database libraries
const dbKit = require("@loke/db-kit");
createConfig(options)
const knex = require("knex");
const dbUri = "postgres://localhost/test-db";
const dbClient = knex(dbKit.knex.createConfig({ connection: dbUri }));
or if you're using a knexfile.js
module.exports = dbKit.knex.createConfig({
connection: process.env.DATABASE_URL || { database: "test-link" }
});
The options are as follows
connection
Gets passed directly to knex
client
The sql client to use, defaults to "pg"
.
migrationsDirectory
Where to place the db migrations, defaults to "./lib/postgres/migrations"
.
async setup(dbClient, logger, options)
const knex = require("knex");
const dbClient = knex(/* ... */);
dbKit.knex.setup(dbClient, console);
Options are:
slowQueryThreshold
Threshold for logging slow queries in ms, defaults to 200
migrateUp
weather or not setup
should migrate the db to the latest schema. Defaults to true
.
registerMetrics(registry)
Regester metrics with prom-client
const { register } = require("prom-client");
dbKit.knex.registerMetrics(register);
formatConnection(connection)
Formats a connection object/string that is valid in knex()
, redacts the password.
console.log("Using database", dbKit.knex.formatConnection(uri));
Bringing this all together you should probably have something like...
knexfile.js
const { knex } = require("@loke/db-kit");
module.exports = knex.createConfig({
connection: process.env.DATABASE_URL || { database: "service-name" }
});
server.js
const dbKit = require("@loke/db-kit");
const lokeLogger = require("@loke/logger");
const promClient = require("prom-client");
const dbConfig = require("./knexfile");
dbKit.knex.registerMetrics(promClient.register);
function main() {
const logger = lokeLogger.create({ metricsRegistry: promClient.register });
logger.info("Using database", dbKit.knex.formatConnection(dbConfig.connection));
const dbClient = knex(dbConfig, logger.withPrefix("db"));
await dbKit.knex.setup(dbClient, dbLogger);
// ...
}
FAQs
Wrapper around knex to provide some sugar such as metrics and slow query logging
The npm package @loke/db-kit receives a total of 80 weekly downloads. As such, @loke/db-kit popularity was classified as not popular.
We found that @loke/db-kit demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.