engine

package
v2.0.5 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: AGPL-3.0 Imports: 12 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) Engine added in v2.0.3

func (c *Connection) Engine() *Engine

Engine returns the underlying engine.

func (*Connection) Execute added in v2.0.3

func (c *Connection) Execute(query string, args ...interface{}) (sql.Result, error)

Execute runs a SQL statement and returns the result.

func (*Connection) GetTableColumns added in v2.0.3

func (c *Connection) GetTableColumns(tbl interface{}) []*table.ColumnRef

GetTableColumns extracts column references from a Table[T] object.

func (*Connection) GetTableName added in v2.0.3

func (c *Connection) GetTableName(tbl interface{}) string

GetTableName extracts the table name from a Table[T] object.

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) QueryRow added in v2.0.3

func (c *Connection) QueryRow(query string, args ...interface{}) *sql.Row

QueryRow executes a query that returns a single row.

func (*Connection) QueryRows added in v2.0.3

func (c *Connection) QueryRows(query string, args ...interface{}) (*sql.Rows, error)

QueryRows executes a query that returns multiple rows.

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
}

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