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) Engine() *Engine
- func (c *Connection) Execute(query string, args ...interface{}) (sql.Result, error)
- func (c *Connection) GetTableColumns(tbl interface{}) []*table.ColumnRef
- func (c *Connection) GetTableName(tbl interface{}) string
- func (c *Connection) InTransaction() bool
- func (c *Connection) QueryRow(query string, args ...interface{}) *sql.Row
- func (c *Connection) QueryRows(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) 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
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.
type EngineOpts ¶ added in v2.0.3
EngineOpts holds engine configuration. Logger is optional and can be used by higher layers to trace SQL statements.