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) Create(ctx context.Context, model 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) First(ctx context.Context, dest any, where string, params 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) Save(ctx context.Context, model any) error
- func (db *DB) Select(ctx context.Context, dest any, where string, params any) error
- func (db *DB) Update(ctx context.Context, model 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.
func (*DB) First ¶ added in v0.50.0
First loads the first row matching where into dest. The where argument may be empty or a SQL fragment without the WHERE keyword.
func (*DB) Save ¶ added in v0.50.0
Save updates every mapped, non-primary-key field using the model's primary key. A primary key is required so Save never accidentally updates a table.
type TableNamer ¶
type TableNamer interface {
TableName() string
}
TableNamer lets a model override the default snake_case table name.