Documentation
¶
Index ¶
- Variables
- type Action
- type Clause
- type Compiler
- type Condition
- func Eq(field string, value any) Condition
- func Gt(field string, value any) Condition
- func Gte(field string, value any) Condition
- func In(field string, value any) Condition
- func Like(field string, value any) Condition
- func Lt(field string, value any) Condition
- func Lte(field string, value any) Condition
- func Neq(field string, value any) Condition
- func Or(c Condition) Condition
- type DB
- func (db *DB) Close() error
- func (db *DB) Create(m fmt.Model) error
- func (db *DB) CreateDatabase(name string) error
- func (db *DB) CreateTable(m fmt.Model) error
- func (db *DB) Delete(m fmt.Model, cond Condition, rest ...Condition) error
- func (db *DB) DropTable(m fmt.Model) error
- func (db *DB) Query(m fmt.Model) *QB
- func (db *DB) RawExecutor() Executor
- func (db *DB) Tx(fn func(tx *DB) error) error
- func (db *DB) Update(m fmt.Model, cond Condition, rest ...Condition) error
- type Executor
- type FieldExt
- type Order
- type OrderClause
- type Plan
- type QB
- func (qb *QB) GroupBy(columns ...string) *QB
- func (qb *QB) Limit(limit int) *QB
- func (qb *QB) Offset(offset int) *QB
- func (qb *QB) Or() *QB
- func (qb *QB) OrderBy(column string) *OrderClause
- func (qb *QB) ReadAll(new func() fmt.Model, onRow func(fmt.Model)) error
- func (qb *QB) ReadOne() error
- func (qb *QB) Where(column string) *Clause
- type Query
- type Rows
- type Scanner
- type TxBoundExecutor
- type TxExecutor
Constants ¶
This section is empty.
Variables ¶
var ErrEmptyTable = fmt.Err("name", "table", "empty")
ErrEmptyTable is returned when ModelName() returns an empty string.
var ErrNoTxSupport = fmt.Err("transaction", "not", "supported")
ErrNoTxSupport is returned by DB.Tx() when the executor does not implement TxExecutor.
var ErrNotFound = fmt.Err("record", "not", "found")
ErrNotFound is returned when ReadOne() finds no matching row.
var ErrValidation = fmt.Err("error", "validation")
ErrValidation is returned when validate() finds a mismatch.
Functions ¶
This section is empty.
Types ¶
type Clause ¶ added in v0.0.8
type Clause struct {
// contains filtered or unexported fields
}
Clause represents an intermediate state for building a query condition.
type Condition ¶
type Condition struct {
// contains filtered or unexported fields
}
Condition represents a filter for a query. It is a sealed value type constructed via helper functions.
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB represents a database connection. Consumers instantiate it via New().
func (*DB) CreateDatabase ¶ added in v0.1.0
CreateDatabase creates a new database.
func (*DB) CreateTable ¶ added in v0.1.0
CreateTable creates a new table for the given model.
func (*DB) Delete ¶
Delete deletes a model from the database. At least one Condition is required. Providing zero conditions is a compile-time error, preventing accidental full-table DELETE statements.
func (*DB) RawExecutor ¶ added in v0.0.10
RawExecutor returns the underlying executor instance.
type Executor ¶ added in v0.0.7
type Executor interface {
Exec(query string, args ...any) error
QueryRow(query string, args ...any) Scanner
Query(query string, args ...any) (Rows, error)
Close() error
}
Executor represents the database connection abstraction. It must remain compatible with sql.DB, sql.Tx, mocks, and WASM drivers.
type FieldExt ¶ added in v0.2.6
type FieldExt struct {
fmt.Field
Ref string // FK: target table name. Empty = no FK.
RefColumn string // FK: target column. Empty = auto-detect PK of Ref table.
}
FieldExt extends fmt.Field with database-specific metadata (foreign keys). Used internally by adapters that support FK constraints.
type Order ¶
type Order struct {
// contains filtered or unexported fields
}
Order represents a sort order for a query. It is a sealed value type constructed via QB.OrderBy().
type OrderClause ¶ added in v0.0.8
type OrderClause struct {
// contains filtered or unexported fields
}
OrderClause represents an intermediate state for building an order by clause.
func (*OrderClause) Asc ¶ added in v0.0.8
func (o *OrderClause) Asc() *QB
Asc sets the order direction to ascending.
func (*OrderClause) Desc ¶ added in v0.0.8
func (o *OrderClause) Desc() *QB
Desc sets the order direction to descending.
type QB ¶
type QB struct {
// contains filtered or unexported fields
}
QB represents a query builder. Consumers hold a *QB reference in variables for incremental building.
func (*QB) OrderBy ¶
func (qb *QB) OrderBy(column string) *OrderClause
OrderBy starts a new order clause for the given column.
type Query ¶
type Query struct {
Action Action
Table string
Database string
Columns []string
Values []any
Conditions []Condition
OrderBy []Order
GroupBy []string
Limit int
Offset int
}
Query represents a database query to be executed by an Executor. Planners read these fields to build Plans.
type TxBoundExecutor ¶ added in v0.0.7
TxBoundExecutor represents an executor bound to a transaction.
type TxExecutor ¶ added in v0.0.7
type TxExecutor interface {
Executor
BeginTx() (TxBoundExecutor, error)
}
TxExecutor represents an executor that supports transactions.