Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
@earnest-labs/microservice-chassis-knex
Advanced tools
A microservice-chassis plugin that provide knex connections
A plugin for microservice-chassis that provides knex database connections
During startup, microservice-chassis-knex
will scan your environment variables
and connect to databases specified there accordingly.
Database connections are specified as environment variables. The name
of each variable takes this form:
KNEX[_{databaseName}]_{setting}
. databaseName
may contain
underscores. If it is not present, the name default
is
used. setting
may be one of JSON
, PGUSER
, PGPASSWORD
,
PGDATABASE
, PGPORT
, or PGHOST
. If JSON
is specified, it is
used to construct a
Knex.Config
object. If not, a blank Knex.Config
is created. Any of the PG*
settings will modify this object with settings appropriate to a
Postgresql database connection.
Sidebar: It is possible that additional database types will be directly supported as environment variable
setting
entries in the future. The current plan is that those will be of the formDBTYPE{SETTING}
. For example, there might beSQLITE3FILENAME
. In the event we go down that road, we will add checks to make sure that you don't mixPG*
settings with other database-specific settings for the samedatabaseName
.
$ npm i --save @earnest-labs/microservice-chassis
$ npm i --save @earnest-labs/microservice-chassis-knex
$ KNEX_JSON='{"client": "sqlite3", "connection": {"filename": ":memory:"}, "useNullAsDefault": true}' \
npx chassis-start
# ^^^ connects to a new in-memory sqlite3 database, accessible as knexPlugin.defaultConnectionName
Ctrl+C
$ KNEX_DB1_PGUSER=theuser \
KNEX_DB1_PGPASSWORD=thepassword \
KNEX_DB1_PGDATABASE=thedatabase \
KNEX_DB1_PGHOST=thehost.dns.record.com \
npx chassis-start
# ^^^ connects to the specified postgresql database, accessible as "DB1"
Ctrl+C
From other microservice-chassis
plugins, you may want to grab a connection and make calls:
import {Plugin} from '@earnest-labs/microservice-chassis/Plugin.js'
import {PluginContext} from '@earnest-labs/microservice-chassis/PluginContext.js'
import {KnexPlugin} from '@earnest-labs/microservice-chassis/knex.chassis-plugin.js'
export const handler = (connection: knex.Knex) => async (request, response) => {
await connection.raw( /* some SQL stuff here */ )
/// ...
}
export const plugin: Plugin = {
name: 'knex-consumer-plugin',
version: '1.0.0',
register: async(context: PluginContext) : Promise<void> {
const knex = context.plugins.get("knex") as KnexPlugin;
const connection = knex.connections.get(knexPlugin.defaultConnectionName);
context.application.get("/route", handler(connection))
}
}
FAQs
A microservice-chassis plugin that provide knex connections
The npm package @earnest-labs/microservice-chassis-knex receives a total of 91 weekly downloads. As such, @earnest-labs/microservice-chassis-knex popularity was classified as not popular.
We found that @earnest-labs/microservice-chassis-knex 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
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.