driver

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2026 License: AGPL-3.0 Imports: 3 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PlaceholderFuncs = map[string]PlaceholderFunc{
	"mysql":     mysqlPlaceholder,
	"oracle":    oraclePlaceholder,
	"postgres":  postgresPlaceholder,
	"sqlite":    sqlitePlaceholder,
	"sqlserver": sqlserverPlaceholder,
	"turso":     sqlitePlaceholder,
}

PlaceholderFuncs contains placeholder functions for different dialects.

Functions

This section is empty.

Types

type Driver

type Driver interface {
	// Open opens a connection to the database.
	Open(dsn string) (*sql.DB, error)
	// Close closes the database connection.
	Close(db *sql.DB) error
	// Ping checks if the database connection is alive.
	Ping(ctx context.Context, db *sql.DB) error
	// BeginTx starts a transaction with the given options.
	BeginTx(ctx context.Context, db *sql.DB, opts *sql.TxOptions) (*sql.Tx, error)
	// Placeholder returns the placeholder format for the driver.
	Placeholder(n int) string
	// Dialect returns the dialect name (mysql, postgres, sqlite, sqlserver, turso).
	Dialect() string
}

Driver defines the interface for database driver implementations.

type MySQL

type MySQL struct{}

MySQL implements the Driver interface for MySQL databases.

func NewMySQL

func NewMySQL() *MySQL

NewMySQL creates a new MySQL driver.

func (*MySQL) BeginTx

func (m *MySQL) BeginTx(ctx context.Context, db *sql.DB, opts *sql.TxOptions) (*sql.Tx, error)

BeginTx starts a MySQL transaction with the given options.

func (*MySQL) Close

func (m *MySQL) Close(db *sql.DB) error

Close closes the MySQL database connection.

func (*MySQL) Dialect

func (m *MySQL) Dialect() string

Dialect returns the dialect name.

func (*MySQL) Open

func (m *MySQL) Open(dsn string) (*sql.DB, error)

Open opens a connection to the MySQL database.

func (*MySQL) Ping

func (m *MySQL) Ping(ctx context.Context, db *sql.DB) error

Ping checks if the MySQL database connection is alive.

func (*MySQL) Placeholder

func (m *MySQL) Placeholder(n int) string

Placeholder returns MySQL-style placeholders (?).

type Oracle added in v0.7.0

type Oracle struct{}

Oracle implements the Driver interface for Oracle databases.

func NewOracle added in v0.7.0

func NewOracle() *Oracle

NewOracle creates a new Oracle driver.

func (*Oracle) BeginTx added in v0.7.0

func (o *Oracle) BeginTx(ctx context.Context, db *sql.DB, opts *sql.TxOptions) (*sql.Tx, error)

BeginTx starts an Oracle transaction with the given options.

func (*Oracle) Close added in v0.7.0

func (o *Oracle) Close(db *sql.DB) error

Close closes the Oracle database connection.

func (*Oracle) Dialect added in v0.7.0

func (o *Oracle) Dialect() string

Dialect returns the dialect name.

func (*Oracle) Open added in v0.7.0

func (o *Oracle) Open(dsn string) (*sql.DB, error)

Open opens a connection to the Oracle database.

func (*Oracle) Ping added in v0.7.0

func (o *Oracle) Ping(ctx context.Context, db *sql.DB) error

Ping checks if the Oracle database connection is alive.

func (*Oracle) Placeholder added in v0.7.0

func (o *Oracle) Placeholder(n int) string

Placeholder returns Oracle-style placeholders (:1, :2, :3).

type PlaceholderFunc

type PlaceholderFunc func(n int) string

PlaceholderFunc is a function that generates placeholders for a given index.

func GetPlaceholderFunc

func GetPlaceholderFunc(dialect string) PlaceholderFunc

GetPlaceholderFunc returns the placeholder function for the given dialect.

type PostgreSQL

type PostgreSQL struct{}

PostgreSQL implements the Driver interface for PostgreSQL databases.

func NewPostgreSQL

func NewPostgreSQL() *PostgreSQL

NewPostgreSQL creates a new PostgreSQL driver.

func (*PostgreSQL) BeginTx

func (p *PostgreSQL) BeginTx(ctx context.Context, db *sql.DB, opts *sql.TxOptions) (*sql.Tx, error)

BeginTx starts a PostgreSQL transaction with the given options.

func (*PostgreSQL) Close

func (p *PostgreSQL) Close(db *sql.DB) error

Close closes the PostgreSQL database connection.

func (*PostgreSQL) Dialect

func (p *PostgreSQL) Dialect() string

Dialect returns the dialect name.

func (*PostgreSQL) Open

func (p *PostgreSQL) Open(dsn string) (*sql.DB, error)

Open opens a connection to the PostgreSQL database.

func (*PostgreSQL) Ping

func (p *PostgreSQL) Ping(ctx context.Context, db *sql.DB) error

Ping checks if the PostgreSQL database connection is alive.

func (*PostgreSQL) Placeholder

func (p *PostgreSQL) Placeholder(n int) string

Placeholder returns PostgreSQL-style placeholders ($1, $2, $3).

type SQLServer

type SQLServer struct{}

SQLServer implements the Driver interface for SQL Server databases.

func NewSQLServer

func NewSQLServer() *SQLServer

NewSQLServer creates a new SQL Server driver.

func (*SQLServer) BeginTx

func (s *SQLServer) BeginTx(ctx context.Context, db *sql.DB, opts *sql.TxOptions) (*sql.Tx, error)

BeginTx starts a SQL Server transaction with the given options.

func (*SQLServer) Close

func (s *SQLServer) Close(db *sql.DB) error

Close closes the SQL Server database connection.

func (*SQLServer) Dialect

func (s *SQLServer) Dialect() string

Dialect returns the dialect name.

func (*SQLServer) Open

func (s *SQLServer) Open(dsn string) (*sql.DB, error)

Open opens a connection to the SQL Server database.

func (*SQLServer) Ping

func (s *SQLServer) Ping(ctx context.Context, db *sql.DB) error

Ping checks if the SQL Server database connection is alive.

func (*SQLServer) Placeholder

func (s *SQLServer) Placeholder(n int) string

Placeholder returns SQL Server-style placeholders (@p1, @p2, @p3).

type SQLite

type SQLite struct{}

SQLite implements the Driver interface for SQLite databases.

func NewSQLite

func NewSQLite() *SQLite

NewSQLite creates a new SQLite driver.

func (*SQLite) BeginTx

func (s *SQLite) BeginTx(ctx context.Context, db *sql.DB, opts *sql.TxOptions) (*sql.Tx, error)

BeginTx starts a SQLite transaction with the given options.

func (*SQLite) Close

func (s *SQLite) Close(db *sql.DB) error

Close closes the SQLite database connection.

func (*SQLite) Dialect

func (s *SQLite) Dialect() string

Dialect returns the dialect name.

func (*SQLite) Open

func (s *SQLite) Open(dsn string) (*sql.DB, error)

Open opens a connection to the SQLite database.

func (*SQLite) Ping

func (s *SQLite) Ping(ctx context.Context, db *sql.DB) error

Ping checks if the SQLite database connection is alive.

func (*SQLite) Placeholder

func (s *SQLite) Placeholder(n int) string

Placeholder returns SQLite-style placeholders (?).

type Turso

type Turso struct{}

Turso implements the Driver interface for Turso databases.

func NewTurso

func NewTurso() *Turso

NewTurso creates a new Turso driver.

func (*Turso) BeginTx

func (t *Turso) BeginTx(ctx context.Context, db *sql.DB, opts *sql.TxOptions) (*sql.Tx, error)

BeginTx starts a Turso transaction with the given options.

func (*Turso) Close

func (t *Turso) Close(db *sql.DB) error

Close closes the Turso database connection.

func (*Turso) Dialect

func (t *Turso) Dialect() string

Dialect returns the dialect name.

func (*Turso) Open

func (t *Turso) Open(dsn string) (*sql.DB, error)

Open opens a connection to the Turso database.

func (*Turso) Ping

func (t *Turso) Ping(ctx context.Context, db *sql.DB) error

Ping checks if the Turso database connection is alive.

func (*Turso) Placeholder

func (t *Turso) Placeholder(n int) string

Placeholder returns SQLite-style placeholders (?) since Turso uses SQLite.

Jump to

Keyboard shortcuts

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