engine

package
v2.0.9 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotInTransaction     = errors.New("connection is not in a transaction")
	ErrAlreadyInTransaction = errors.New("connection is already in a transaction")
)

Functions

This section is empty.

Types

type Connection added in v2.0.3

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

Connection represents a database connection/transaction context.

func (*Connection) Begin added in v2.0.3

func (c *Connection) Begin() error

Begin starts a transaction on the connection.

func (*Connection) Close added in v2.0.3

func (c *Connection) Close() error

Close closes the connection and rolls back if needed.

func (*Connection) Commit added in v2.0.3

func (c *Connection) Commit() error

Commit commits the transaction.

func (*Connection) Context added in v2.0.3

func (c *Connection) Context() context.Context

Context returns the connection context.

func (*Connection) Dialect added in v2.0.7

func (c *Connection) Dialect() dialect.Dialect

Dialect returns the SQL dialect for this connection.

func (*Connection) Engine added in v2.0.3

func (c *Connection) Engine() *Engine

Engine returns the underlying engine.

func (*Connection) ExecuteContext added in v2.0.6

func (c *Connection) ExecuteContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

ExecuteContext runs a SQL statement with the provided context.

func (*Connection) InTransaction added in v2.0.3

func (c *Connection) InTransaction() bool

InTransaction returns true if the connection is in a transaction.

func (*Connection) Logger added in v2.0.7

func (c *Connection) Logger() *slog.Logger

Logger returns the configured logger for this connection.

func (*Connection) QueryRowContext added in v2.0.6

func (c *Connection) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row

QueryRowContext executes a query that returns a single row with the provided context.

func (*Connection) QueryRowsContext added in v2.0.6

func (c *Connection) QueryRowsContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

QueryRowsContext executes a query that returns multiple rows with the provided context.

func (*Connection) Rollback added in v2.0.3

func (c *Connection) Rollback() error

Rollback rolls back the transaction.

type Engine

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

Engine manages database configuration and connections.

func NewEngine

func NewEngine(connectionURL string, opts EngineOpts) (*Engine, error)

NewEngine creates a new database engine from a SQLAlchemy-style connection URL, e.g. "sqlite+pysqlite:///:memory:" or "postgresql+psycopg2://user:pass@host/db". It opens the underlying database with sql.Open and selects the dialect driver (placeholder/quoting behaviour) based on the URL scheme.

func (*Engine) Autocommit added in v2.0.3

func (e *Engine) Autocommit() bool

Autocommit returns whether the engine defaults to autocommit connections.

func (*Engine) Connect added in v2.0.3

func (e *Engine) Connect(ctx context.Context) (*Connection, error)

Connect creates a new database connection using the engine configuration.

func (*Engine) ConnectionInfo added in v2.0.3

func (e *Engine) ConnectionInfo() *connectionInfo

ConnectionInfo returns the parsed connection information for the engine.

func (*Engine) Dialect

func (e *Engine) Dialect() dialect.Dialect

Dialect returns the configured SQL dialect (placeholder/quoting behaviour).

func (*Engine) Logger

func (e *Engine) Logger() *slog.Logger

Logger returns the configured logger (may be nil).

type EngineOpts added in v2.0.3

type EngineOpts struct {
	Logger     *slog.Logger
	Autocommit bool
	Ping       bool // TODO implement ping when connect if driver support it
}

EngineOpts holds engine configuration. Logger is optional and can be used by higher layers to trace SQL statements.

Jump to

Keyboard shortcuts

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