orm

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: MIT Imports: 1 Imported by: 0

README

tinywasm/orm

Project Badges

Tiny ORM database adapter for WebAssembly.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyTable = fmt.Err("name", "table", "empty")

ErrEmptyTable is returned when TableName() returns an empty string.

View Source
var ErrNoTxSupport = fmt.Err("transaction", "not", "supported")

ErrNoTxSupport is returned by DB.Tx() when the adapter does not implement TxAdapter.

View Source
var ErrNotFound = fmt.Err("record", "not", "found")

ErrNotFound is returned when ReadOne() finds no matching row.

View Source
var ErrValidation = fmt.Err("error", "validation")

ErrValidation is returned when validate() finds a mismatch.

Functions

This section is empty.

Types

type Action

type Action int

Action represents the type of database operation.

const (
	ActionCreate Action = iota
	ActionReadOne
	ActionUpdate
	ActionDelete
	ActionReadAll
)

type Adapter

type Adapter interface {
	Execute(q Query, m Model, factory func() Model, each func(Model)) error
}

Adapter represents a database adapter. Consumers inject this interface.

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.

func Eq

func Eq(field string, value any) Condition

Eq creates a condition for checking equality.

func Gt

func Gt(field string, value any) Condition

Gt creates a condition for checking if a value is greater than another.

func Gte

func Gte(field string, value any) Condition

Gte creates a condition for checking if a value is greater than or equal to another.

func Like

func Like(field string, value any) Condition

Like creates a condition for checking if a value matches a pattern.

func Lt

func Lt(field string, value any) Condition

Lt creates a condition for checking if a value is less than another.

func Lte

func Lte(field string, value any) Condition

Lte creates a condition for checking if a value is less than or equal to another.

func Neq

func Neq(field string, value any) Condition

Neq creates a condition for checking inequality.

func Or

func Or(c Condition) Condition

Or creates a condition with OR logic.

func (Condition) Field

func (c Condition) Field() string

func (Condition) Logic

func (c Condition) Logic() string

func (Condition) Operator

func (c Condition) Operator() string

func (Condition) Value

func (c Condition) Value() any

type DB

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

DB represents a database connection. Consumers instantiate it via New().

func New

func New(adapter Adapter) *DB

New creates a new DB instance.

func (*DB) Create

func (db *DB) Create(m Model) error

Create inserts a new model into the database.

func (*DB) Delete

func (db *DB) Delete(m Model, conds ...Condition) error

Delete deletes a model from the database.

func (*DB) Query

func (db *DB) Query(m Model) *QB

Query creates a new QB instance.

func (*DB) Tx

func (db *DB) Tx(fn func(tx *DB) error) error

Tx executes a function within a transaction.

func (*DB) Update

func (db *DB) Update(m Model, conds ...Condition) error

Update updates a model in the database.

type Model

type Model interface {
	TableName() string
	Columns() []string
	Values() []any
	Pointers() []any
}

Model represents a database model. Consumers implement this interface.

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().

func (Order) Column

func (o Order) Column() string

func (Order) Dir

func (o Order) Dir() string

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) GroupBy

func (qb *QB) GroupBy(columns ...string) *QB

GroupBy adds a group by clause to the query.

func (*QB) Limit

func (qb *QB) Limit(limit int) *QB

Limit sets the limit for the query.

func (*QB) Offset

func (qb *QB) Offset(offset int) *QB

Offset sets the offset for the query.

func (*QB) OrderBy

func (qb *QB) OrderBy(column, dir string) *QB

OrderBy adds an order clause to the query.

func (*QB) ReadAll

func (qb *QB) ReadAll(factory func() Model, each func(Model)) error

ReadAll executes the query and returns all results.

func (*QB) ReadOne

func (qb *QB) ReadOne() error

ReadOne executes the query and returns a single result.

func (*QB) Where

func (qb *QB) Where(conds ...Condition) *QB

Where adds conditions to the query.

type Query

type Query struct {
	Action     Action
	Table      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 Adapter. Adapters read these fields to build native queries.

type TxAdapter

type TxAdapter interface {
	Adapter
	BeginTx() (TxBound, error)
}

TxAdapter represents an adapter that supports transactions.

type TxBound

type TxBound interface {
	Adapter
	Commit() error
	Rollback() error
}

TxBound represents a transaction bound to an adapter.

Jump to

Keyboard shortcuts

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