Documentation
¶
Overview ¶
Package tinyorm provides a deliberately small ORM layer for tinySQL.
It focuses on the pieces that are useful for embedded tools: struct mapping, additive table creation, named parameters, and simple primary-key CRUD.
Index ¶
- Variables
- func BindNamed(sql string, params any) (string, error)
- func Columns(model any) ([]string, error)
- type DB
- func (db *DB) AutoMigrate(ctx context.Context, models ...any) error
- func (db *DB) DeleteByPK(ctx context.Context, model any, pk any) error
- func (db *DB) Exec(ctx context.Context, sql string, params any) (*tinysql.ResultSet, error)
- func (db *DB) FindByPK(ctx context.Context, dest any, pk any) error
- func (db *DB) Insert(ctx context.Context, model any) error
- func (db *DB) Query(ctx context.Context, sql string, params any) (*tinysql.ResultSet, error)
- func (db *DB) Select(ctx context.Context, dest any, where string, params any) error
- type TableNamer
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = fmt.Errorf("tinyorm: not found")
ErrNotFound is returned when FindByPK finds no matching row.
Functions ¶
Types ¶
type DB ¶
DB wraps a tinySQL database with a tenant for ORM operations.
func (*DB) AutoMigrate ¶
AutoMigrate creates tables for the supplied models when they do not exist. It is intentionally additive-only; it never drops or rewrites tables.
func (*DB) DeleteByPK ¶
DeleteByPK deletes one row by primary key.
func (*DB) FindByPK ¶
FindByPK loads one row by primary key into dest, which must be a pointer to a struct.
type TableNamer ¶
type TableNamer interface {
TableName() string
}
TableNamer lets a model override the default snake_case table name.