tinyorm

package
v0.32.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var ErrNotFound = fmt.Errorf("tinyorm: not found")

ErrNotFound is returned when FindByPK finds no matching row.

Functions

func BindNamed

func BindNamed(sql string, params any) (string, error)

BindNamed replaces :name and @name placeholders outside SQL string literals.

func Columns

func Columns(model any) ([]string, error)

Columns returns mapped column names for a model. It is useful for demos and generated SQL in applications that want to stay explicit.

Types

type DB

type DB struct {
	Raw    *tinysql.DB
	Tenant string
}

DB wraps a tinySQL database with a tenant for ORM operations.

func New

func New(db *tinysql.DB, tenant string) *DB

New creates an ORM handle. Empty tenant defaults to "default".

func (*DB) AutoMigrate

func (db *DB) AutoMigrate(ctx context.Context, models ...any) error

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

func (db *DB) DeleteByPK(ctx context.Context, model any, pk any) error

DeleteByPK deletes one row by primary key.

func (*DB) Exec

func (db *DB) Exec(ctx context.Context, sql string, params any) (*tinysql.ResultSet, error)

Exec executes SQL after replacing :name or @name placeholders from params.

func (*DB) FindByPK

func (db *DB) FindByPK(ctx context.Context, dest any, pk any) error

FindByPK loads one row by primary key into dest, which must be a pointer to a struct.

func (*DB) Insert

func (db *DB) Insert(ctx context.Context, model any) error

Insert inserts one struct value.

func (*DB) Query

func (db *DB) Query(ctx context.Context, sql string, params any) (*tinysql.ResultSet, error)

Query executes SQL after replacing :name or @name placeholders from params.

func (*DB) Select

func (db *DB) Select(ctx context.Context, dest any, where string, params any) error

Select loads rows into dest, which must be a pointer to a slice of structs. The where argument may be empty or a SQL fragment without the WHERE keyword.

type TableNamer

type TableNamer interface {
	TableName() string
}

TableNamer lets a model override the default snake_case table name.

Jump to

Keyboard shortcuts

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