dbdsn

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package dbdsn reads the DSNs of MySQL/MariaDB and PostgreSQL databases the way their drivers do, for the state components and the data module alike. A DSN holds a password, so no error of this package carries the DSN or any part of it: a parse error of net/url or of a driver quotes the text it could not read, which may be the password itself.

Index

Constants

View Source
const (
	MySQL    = "mysql" // MySQL and MariaDB
	Postgres = "postgres"
)

Drivers.

Variables

This section is empty.

Functions

func Hosts

func Hosts(driver, dsn string) ([]string, error)

Hosts lists every host the driver may connect to with the DSN, as the driver itself reads it (PostgreSQL: several hosts, fallbacks, host= parameters, PG* variables); "" stands for a local socket.

func MySQLConfig

func MySQLConfig(dsn string) (*mysql.Config, error)

MySQLConfig accepts mysql://user:pass@host:port/ (or mariadb://) and the driver's own form (user:pass@tcp(host:port)/). The database in it is ignored. The URL takes the parameters of mysqlParams; any other is an error, so a connection is never made without the TLS it asked for. The driver's form takes the driver's own parameters. DriftGate's connections use the text protocol: no server-side prepared statements, so every value arrives as its text and Com_stmt_execute is left to the application, and no multi-statements.

func PostgresURL

func PostgresURL(dsn string) (*url.URL, error)

PostgresURL reads a postgres:// (or postgresql://) URL; a URL without a database gets postgres.

func Server

func Server(driver, dsn string) (string, error)

Server names the server a DSN connects to, without the user or password: the network and address for MySQL (tcp(127.0.0.1:3306), unix(/tmp/s)), every host:port in order for PostgreSQL. Two DSNs with the same server reach the same databases.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL