connection

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2025 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoTransaction = errors.New("no transaction")
)
View Source
var (
	ErrTransactionAlreadyOpened = errors.New("transaction already opened")
)

Functions

func ContextWithTx added in v1.2.0

func ContextWithTx(parent context.Context, v sqlex.Tx) context.Context

func TxFromContext added in v1.2.0

func TxFromContext(parent context.Context) (sqlex.Tx, error)

Types

type Connection

type Connection struct {
	// contains filtered or unexported fields
}

func New

func New(dsn string) (*Connection, error)

func (*Connection) Close added in v1.2.0

func (c *Connection) Close() error

func (*Connection) DSN

func (c *Connection) DSN() string

DSN returns the connection string.

func (*Connection) Driver

func (c *Connection) Driver() Driver

Driver returns the driver name used to connect to the database.

func (*Connection) ExecContext

func (c *Connection) ExecContext(ctx context.Context, query string, args ...any) (sqlex.Result, error)

ExecContext executes a query without returning any rows. The args are for any placeholder parameters in the query.

func (*Connection) Ping

func (c *Connection) Ping() error

Ping checks connection

func (*Connection) QueryContext

func (c *Connection) QueryContext(ctx context.Context, query string, args ...any) (sqlex.Rows, error)

QueryContext executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.

func (*Connection) Transaction

func (c *Connection) Transaction(ctx context.Context, txFn func(ctx context.Context) error) error

Transaction executes body in func txFn into transaction.

type DBExecutor added in v1.2.0

type DBExecutor interface {
	ExecContext(ctx context.Context, query string, args ...any) (sqlex.Result, error)
}

type DBPinger added in v1.2.0

type DBPinger interface {
	Ping() error
}

type DBQuerier added in v1.2.0

type DBQuerier interface {
	QueryContext(ctx context.Context, query string, args ...any) (sqlex.Rows, error)
}

type DBTransactor added in v1.2.0

type DBTransactor interface {
	BeginTx(ctx context.Context, opts *sql.TxOptions) (sqlex.Tx, error)
}

type Driver

type Driver string
const (
	DriverClickhouse Driver = "clickhouse"
	DriverMySQL      Driver = "mysql"
	DriverPostgres   Driver = "postgres"
	DriverTarantool  Driver = "tarantool"
)

func (Driver) String

func (d Driver) String() string

type SQLDB added in v1.2.0

type SQLDB interface {
	DBPinger
	DBQuerier
	DBExecutor
	DBTransactor
	io.Closer
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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