drivers

package
v0.0.0-...-a3191f8 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2025 License: MIT Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterDriver

func RegisterDriver(d Driver)

RegisterDriver registers a new Driver.

func Test

func Test() func()

TODO: temporarily.

Types

type Driver

type Driver interface {
	// Name of this driver.
	Name() string

	// SQL dialect for the database engine; "sqlite", "postgresql", or "mysql".
	Dialect() string

	// Connect to the database with the given connect string, which has
	// everything before the "+" removed.
	//
	// If create is true, it should attempt to create the database if it doesn't
	// exist.
	//
	// It may optionally return a driverConn, for example *pgxpool.Pool. This
	// can be nil.
	Connect(ctx context.Context, connect string, create bool) (db *sql.DB, driverConn any, err error)

	// ErrUnique reports if this error reports a UNIQUE constraint violation.
	ErrUnique(error) bool

	// Start a new test. This is expected to set up a temporary database which
	// is cleaned at the end.
	StartTest(*testing.T, *TestOptions) context.Context
}

Driver for a SQL connection.

func Drivers

func Drivers() []Driver

Drivers returns a list of currently registered drivers.

type NotExistError

type NotExistError struct {
	Driver  string // Driver name
	DB      string // Database name
	Connect string // Full connect string
}

NotExistError is returned by a driver when a database doesn't exist and Create is false in the connection arguments.

func (NotExistError) Error

func (err NotExistError) Error() string

type TestOptions

type TestOptions struct {
	Connect      string
	Files        fs.FS
	GoMigrations map[string]func(context.Context) error
}

TestOptions are options to pass to zdb.Connect() in the StartTest() method.

This needs to be a new type to avoid import cycles.

Directories

Path Synopsis
Package sqlite3 provides a zdb driver for SQLite.
Package sqlite3 provides a zdb driver for SQLite.
Package mariadb provides a zdb driver for MariaDB.
Package mariadb provides a zdb driver for MariaDB.
Package pgx provides a zdb driver for PostgreSQL.
Package pgx provides a zdb driver for PostgreSQL.
Package pq provides a zdb driver for PostgreSQL.
Package pq provides a zdb driver for PostgreSQL.

Jump to

Keyboard shortcuts

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