zdbzgo.at/zdb/drivers Index | Files | Directories

package drivers

import "zgo.at/zdb/drivers"

Index

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.
	Connect(ctx context.Context, connect string, create bool) (*sql.DB, bool, 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
}

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

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

Source Files

drivers.go

Directories

PathSynopsis
drivers/go-sqlite3Package sqlite3 provides a zdb driver for SQLite.
drivers/mariadbPackage mariadb provides a zdb driver for MariaDB.
drivers/pgxPackage pgx provides a zdb driver for PostgreSQL.
drivers/pqPackage pq provides a zdb driver for PostgreSQL.
drivers/test
Version
v0.0.0-20231215032724-5a11cacffebe (latest)
Published
Dec 15, 2023
Platform
linux/amd64
Imports
6 packages
Last checked
1 month ago

Tools for package owners.