Documentation
¶
Overview ¶
Package orm is a small, driver-agnostic, Eloquent-style query builder over database/sql. The dialect (placeholder style, ILIKE handling) is chosen from the configured driver, so models are written once and the driver is swapped from .env (DB_DRIVER) without changing code.
models.Posts(app).Find(ctx, id)
models.Posts(app).Where("title", "ILIKE", "%go%").Order("created_at DESC").Get(ctx)
Index ¶
- type Dialect
- type Query
- func (q *Query[T]) Create(ctx context.Context, data map[string]any) (*T, error)
- func (q *Query[T]) Delete(ctx context.Context) error
- func (q *Query[T]) Find(ctx context.Context, id any) (*T, error)
- func (q *Query[T]) First(ctx context.Context) (*T, error)
- func (q *Query[T]) Get(ctx context.Context) ([]T, error)
- func (q *Query[T]) Limit(n int) *Query[T]
- func (q *Query[T]) Offset(n int) *Query[T]
- func (q *Query[T]) Order(s string) *Query[T]
- func (q *Query[T]) Update(ctx context.Context, data map[string]any) error
- func (q *Query[T]) Where(col, op string, val any) *Query[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dialect ¶
Dialect is the kernel's per-driver SQL dialect (re-exported for convenience).
func DialectFor ¶
DialectFor returns the dialect for a database/sql driver name.
type Query ¶
type Query[T any] struct { // contains filtered or unexported fields }
Query is a fluent, typed query builder for table rows scanned into T.
func (*Query[T]) Order ¶
Order sets the ORDER BY clause (e.g. "created_at DESC"). Validated against an identifier+direction allowlist.
Click to show internal directories.
Click to hide internal directories.