Documentation
¶
Overview ¶
Package connect opens a dbtestify.DBConnector from a connection string.
It is separate from the core dbtestify package because it registers the SQLite, PostgreSQL, and MySQL database/sql drivers. Consumers that already own a *sql.DB use dbtestify.NewDBConnectorFromDB instead and never pay for those dependencies, which keeps the core package free of cgo.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewDBConnector ¶
NewDBConnector creates a new dbtestify.DBConnector based on the provided source string. The source string should be in the format of "mysql://", "sqlite://", or "postgres://".
The context is used to manage the lifecycle of the database connection. So you should pass a context that can be cancelled. The returned DBConnector owns the *sql.DB it opened and closes it when ctx is done. Use dbtestify.NewDBConnectorFromDB instead when the caller already owns the pool.
This package uses https://github.com/jackc/pgx for PostgreSQL, https://github.com/go-sql-driver/mysql for MySQL, https://github.com/mattn/go-sqlite3 for SQLite3. To study the detail of the connection string, check the documentation of each driver.
- postgres://user:pass@localhost:5432/dbname?sslmode=disable
- mysql://root:pass@tcp(localhost:3306)/foo?tls=skip-verify
- sqlite://file:dbfilename.db
Types ¶
This section is empty.