Documentation
¶
Index ¶
- Variables
- type Connection
- func (c *Connection) Begin() error
- func (c *Connection) Close() error
- func (c *Connection) Commit() error
- func (c *Connection) Context() context.Context
- func (c *Connection) Dialect() dialect.Dialect
- func (c *Connection) Engine() *Engine
- func (c *Connection) ExecuteContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (c *Connection) InTransaction() bool
- func (c *Connection) Logger() *slog.Logger
- func (c *Connection) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
- func (c *Connection) QueryRowsContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- func (c *Connection) Rollback() error
- type Engine
- type EngineOpts
Constants ¶
This section is empty.
Variables ¶
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
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.