Driver & ORM Exporters
Parse once, export to whatever your stack needs. All exporters return decoded (raw) credentials — exactly what drivers expect.
| Method | Returns | For |
|---|---|---|
toKnexConnection() / toKnex() | object | Knex.js |
toSequelize() | object | Sequelize |
toTypeORM() | object | TypeORM |
toPrisma() | URL string | Prisma |
toMongo() | options object | MongoDB native driver |
toRedis() | options object | node-redis / ioredis |
toSolrConnection() / toSolr() | object | solr-client |
toHttpUrl() | URL string | HTTP clients |
toStandardConnection() | { url, username, password } | generic clients |
toObject() | merged plain object | your own code |
Knex
const conn = new Connection('postgres://admin:pw@db.example.com:5433/orders')
require('knex')({
client: 'pg',
connection: conn.toKnexConnection()
// { host: 'db.example.com', user: 'admin', password: 'pw',
// port: 5433, database: 'orders' }
})Sequelize
Protocol maps to dialect (postgres/postgresql → postgres, mysql, mariadb, mssql, sqlite). Query parameters become dialectOptions:
const conn = new Connection('postgres://admin:pw@db.example.com/orders?ssl=true')
new Sequelize(conn.toSequelize())
// { dialect: 'postgres', host: 'db.example.com', port: 5432,
// database: 'orders', username: 'admin', password: 'pw',
// dialectOptions: { ssl: 'true' } }TypeORM
Same protocol mapping (plus mongodb); query parameters become extra:
const conn = new Connection('mysql://app:pw@db.example.com/shop')
new DataSource({ ...conn.toTypeORM(), entities: [/* ... */] })
// { type: 'mysql', host: 'db.example.com', port: 3306,
// database: 'shop', username: 'app', password: 'pw' }Prisma
Prisma consumes URLs directly — toPrisma() returns the canonical URL string (alias for toUrl()):
process.env.DATABASE_URL = conn.toPrisma()MongoDB
Builds a native-driver options object. authSource comes from the query param, then the database path, then 'admin'; ssl reflects the secure flag or ssl/tls params; remaining query params are copied through (with prototype-pollution protection):
const conn = new Connection('mongodb://app:pw@db1:27017,db2:27018/orders?replicaSet=rs0')
conn.toMongo()
// { authSource: 'orders', replicaSet: 'rs0', ssl: false,
// auth: { username: 'app', password: 'pw' } }TIP
For the connection string itself (e.g. MongoClient(url)), use toUrl() — multi-host lists round-trip correctly.
Redis
The path becomes the database number; rediss:// or a secure flag adds tls: {}:
new Connection('rediss://default:pw@cache.example.com/2').toRedis()
// { host: 'cache.example.com', port: 6379, db: 2,
// password: 'pw', username: 'default', tls: {} }Solr
Requires an http/https protocol (throws ProtocolError otherwise). Port defaults to 8983:
new Connection('http://solr.example.com:8983/solr/core1').toSolrConnection()
// { host: 'solr.example.com', username: '', password: '',
// port: 8983, bigint: true, secure: false, path: '/solr/core1' }HTTP
toHttpUrl() is toUrl() with a guard — it throws ProtocolError unless the protocol is http or https:
new Connection('https://api.example.com/v2').toHttpUrl()
// 'https://api.example.com/v2'
new Connection('postgres://db.example.com/app').toHttpUrl()
// throws ProtocolErrorStandard
A minimal { url, username, password } shape (URL without path/params):
new Connection('http://u:p@example.com:8080/path').toStandardConnection()
// { url: 'http://example.com:8080', username: 'u', password: 'p' }Writing your own
Everything is on connection and auth — compose freely:
function toPgPool (conn) {
return {
host: conn.connection.hostname,
port: conn.connection.port,
database: conn.connection.path.replace(/^\//, ''),
user: conn.auth.username,
password: conn.auth.password,
ssl: conn.connection.secure
}
}