DSN parsing for PostgreSQL connection strings.
Supports both libpq formats:
- keyword=value: host=localhost port=5432 dbname=test
- URI: postgresql://user:pass@host:port/db?param=value
Re-exported through pg_connection.nim; depends only on types.nim (in particular, does not touch PgConnection).
Procs
proc applyParam(result: var ConnConfig; key, val: string) {....raises: [PgError, PgError, PgError, PgError, PgError, PgError, PgError, PgError], tags: [ReadIOEffect], forbids: [].}
- Apply a single connection parameter to a ConnConfig.
proc initConnConfig(host = "127.0.0.1"; port = 5432; user = ""; password = ""; database = ""; sslMode = sslDisable; sslRootCert = ""; channelBinding = cbPrefer; applicationName = ""; connectTimeout = ZeroDuration; keepAlive = true; keepAliveIdle = 0; keepAliveInterval = 0; keepAliveCount = 0; hosts: seq[HostEntry] = @[]; targetSessionAttrs = tsaAny; requireAuth: set[AuthMethod] = {}; extraParams: seq[(string, string)] = @[]; maxMessageSize = 0): ConnConfig {. ...raises: [], tags: [], forbids: [].}
- Create a connection configuration with sensible defaults. For DSN-based configuration, use parseDsn instead.
proc parseAuthMethod(s: string): AuthMethod {....raises: [PgError], tags: [], forbids: [].}
proc parseChannelBindingMode(s: string): ChannelBindingMode {....raises: [PgError], tags: [], forbids: [].}
proc parseDsn(dsn: string): ConnConfig {....raises: [PgError], tags: [ReadIOEffect], forbids: [].}
-
Parse a PostgreSQL connection string into a ConnConfig.
Supports two formats:
- URI: postgresql://[user[:password]@][host[:port]][/database][?param=value&...]
- keyword=value: host=localhost port=5432 dbname=test (libpq compatible)
Both postgresql:// and postgres:// schemes are accepted for URI format.
proc parseKeyValueDsn(dsn: string): ConnConfig {....raises: [PgError], tags: [ReadIOEffect], forbids: [].}
-
Parse a libpq keyword=value connection string into a ConnConfig.
Format: host=localhost port=5432 dbname=test user=myuser
Values may be single-quoted: password='has spaces' Within quoted values, \' and \\ are escape sequences.
proc parsePort(s: string): int {....raises: [PgError], tags: [], forbids: [].}
proc parseRequireAuth(s: string): set[AuthMethod] {....raises: [PgError], tags: [], forbids: [].}
- Parse a comma-separated list of auth method names into a set (libpq require_auth syntax; negation prefix ! is not yet supported). Empty input returns the empty set (allow any).
proc parseSslMode(s: string): SslMode {....raises: [PgError], tags: [], forbids: [].}
proc parseTargetSessionAttrs(s: string): TargetSessionAttrs {....raises: [PgError], tags: [], forbids: [].}
proc parseUriDsn(dsn: string): ConnConfig {....raises: [PgError], tags: [ReadIOEffect], forbids: [].}
- Parse a PostgreSQL URI connection string into a ConnConfig.