Skip to content

Types & Schemas

Shipped in index.d.ts. In TypeScript, the namespace types hang off the default export:

ts
import Connection = require('parse-connection-url')

const conn: Connection = new Connection(process.env.DATABASE_URL!)
const hosts: Connection.Host[] = conn.getHosts()
const knex: Connection.KnexConnection = conn.toKnexConnection()

ConnectionSchema

The shape of conn.connection:

FieldTypeNotes
protocolstringe.g. 'postgres'
hostnamestringprimary host
portnumberexplicit or protocol default; 0 is honored
pathstringleading /
securebooleanfrom the secure-protocols list
paramsRecord<string, string>query parameters
fragmentstringhash without #
hostsHost[]populated for multi-host URLs
typestringparser category: http, sql, nosql, queue, search, kv, ftp, tcp, udp, connectionString, generic
prefixstring'jdbc' / 'odbc' for prefixed connection strings
ipVersion4 | 6set when the host is an IP literal

AuthSchema

The shape of conn.auth. Values are stored decoded — see Security.

FieldType
usernamestring
passwordstring

Host

ts
interface Host {
  hostname: string
  port: number
}

ConnectionInput

Accepted by the constructor / Connection.from / Connection.parse — all fields optional, with aliases:

ts
interface ConnectionInput {
  url?: string; uri?: string; jdbcUrl?: string; jdbcurl?: string
  hostname?: string; host?: string
  port?: number
  protocol?: string
  path?: string; database?: string
  prefix?: string; type?: string
  username?: string; user?: string; principal?: string
  password?: string; pass?: string
  auth?: Partial<AuthSchema> & { user?: string; principal?: string; pass?: string }
  connection?: Partial<ConnectionSchema>
}

ConnectionOptions

ts
interface ConnectionOptions {
  secureConnectionProtocols?: string[]
}

Exporter return types

TypeReturned byShape
KnexConnectiontoKnexConnection(){ host, user, password, port, database }
SequelizeConfigtoSequelize(){ dialect, host, port, database, username, password, dialectOptions? }
TypeORMConfigtoTypeORM(){ type, host, port, database, username, password, extra? }
MongoOptionstoMongo(){ authSource, replicaSet?, ssl, auth?, ...params }
RedisOptionstoRedis(){ host, port, db, password?, username?, tls? }
SolrConnectiontoSolrConnection(){ host, username, password, port, bigint, secure, path }
StandardConnectiontoStandardConnection(){ url, username, password }
JSONOutputtoJSON(){ url, connection, auth } — masked

Released under the MIT License.