session

package
v2.0.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotInTransaction is returned when attempting transaction operations outside a transaction
	ErrNotInTransaction = errors.New("session is not in a transaction")

	// ErrAlreadyInTransaction is returned when attempting to start a transaction while already in one
	ErrAlreadyInTransaction = errors.New("session is already in a transaction")
)

Functions

This section is empty.

Types

type Driver

type Driver interface {
	// Placeholder returns the placeholder format for this driver
	// e.g., "?" for SQLite/MySQL, "$" for Postgres
	Placeholder(position int) string

	// SupportsReturning indicates if the driver supports RETURNING clauses
	SupportsReturning() bool

	// Quote quotes an identifier (table/column name)
	Quote(identifier string) string
}

Driver represents a SQL dialect driver

func DriverByName

func DriverByName(name string) (Driver, error)

DriverByName returns a driver by name

type Engine

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

Engine manages database connections and sessions

func NewEngine

func NewEngine(db *sql.DB, opts ...EngineOption) *Engine

NewEngine creates a new database engine

func (*Engine) Begin

func (e *Engine) Begin() (*Session, error)

Begin starts a new transaction and returns a session bound to it

func (*Engine) BeginWithContext

func (e *Engine) BeginWithContext(ctx context.Context) (*Session, error)

BeginWithContext starts a new transaction with a context

func (*Engine) Close

func (e *Engine) Close() error

Close closes the database connection

func (*Engine) DB

func (e *Engine) DB() *sql.DB

DB returns the underlying database connection

func (*Engine) Driver

func (e *Engine) Driver() Driver

Driver returns the SQL driver

func (*Engine) NewSession

func (e *Engine) NewSession() *Session

NewSession creates a new session for executing queries

func (*Engine) NewSessionWithContext

func (e *Engine) NewSessionWithContext(ctx context.Context) *Session

NewSessionWithContext creates a new session with a context

type EngineConfig

type EngineConfig struct {
	Driver Driver
	Debug  bool // Log SQL statements
}

EngineConfig holds engine configuration

type EngineOption

type EngineOption func(*EngineConfig)

EngineOption is a functional option for configuring an Engine

func WithDebug

func WithDebug(debug bool) EngineOption

WithDebug enables debug logging

func WithDriver

func WithDriver(driver Driver) EngineOption

WithDriver sets the SQL driver

type MySQLDriver

type MySQLDriver struct{}

MySQLDriver implements the Driver interface for MySQL

func (*MySQLDriver) Placeholder

func (d *MySQLDriver) Placeholder(position int) string

func (*MySQLDriver) Quote

func (d *MySQLDriver) Quote(identifier string) string

func (*MySQLDriver) SupportsReturning

func (d *MySQLDriver) SupportsReturning() bool

type PostgresDriver

type PostgresDriver struct{}

PostgresDriver implements the Driver interface for PostgreSQL

func (*PostgresDriver) Placeholder

func (d *PostgresDriver) Placeholder(position int) string

func (*PostgresDriver) Quote

func (d *PostgresDriver) Quote(identifier string) string

func (*PostgresDriver) SupportsReturning

func (d *PostgresDriver) SupportsReturning() bool

type SQLiteDriver

type SQLiteDriver struct{}

SQLiteDriver implements the Driver interface for SQLite

func (*SQLiteDriver) Placeholder

func (d *SQLiteDriver) Placeholder(position int) string

func (*SQLiteDriver) Quote

func (d *SQLiteDriver) Quote(identifier string) string

func (*SQLiteDriver) SupportsReturning

func (d *SQLiteDriver) SupportsReturning() bool

type Session

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

Session represents a database session for executing queries

func (*Session) Close

func (s *Session) Close() error

Close closes the session (rolls back transaction if active)

func (*Session) Commit

func (s *Session) Commit() error

Commit commits the transaction (only valid if session is in a transaction)

func (*Session) Context

func (s *Session) Context() context.Context

Context returns the session context

func (*Session) Delete

func (s *Session) Delete(tbl interface{}) *query.DeleteBuilder

Delete creates a new DELETE query builder

func (*Session) Engine

func (s *Session) Engine() *Engine

Engine returns the underlying engine

func (*Session) Exec

func (s *Session) Exec(query string, args ...interface{}) (sql.Result, error)

Exec executes a raw SQL statement

func (*Session) GetTableColumns

func (s *Session) GetTableColumns(tbl interface{}) []*table.ColumnRef

GetTableColumns extracts column references from a Table[T] object

func (*Session) GetTableName

func (s *Session) GetTableName(tbl interface{}) string

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

func (*Session) InTransaction

func (s *Session) InTransaction() bool

InTransaction returns true if the session is in a transaction

func (*Session) Insert

func (s *Session) Insert(tbl interface{}) *query.InsertBuilder

Insert creates a new INSERT query builder

func (*Session) Query

func (s *Session) Query(tbl interface{}) *query.SelectBuilder

Query creates a new SELECT query builder

func (*Session) QueryRow

func (s *Session) QueryRow(query string, args ...interface{}) *sql.Row

QueryRow executes a query that returns a single row

func (*Session) QueryRows

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

QueryRows executes a query that returns multiple rows

func (*Session) Rollback

func (s *Session) Rollback() error

Rollback rolls back the transaction (only valid if session is in a transaction)

func (*Session) Update

func (s *Session) Update(tbl interface{}) *query.UpdateBuilder

Update creates a new UPDATE query builder

Jump to

Keyboard shortcuts

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