query

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package query is a Knex-style fluent query builder for tables without a model. Builders are mutable: every method modifies and returns the same *Builder.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

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

func Table

func Table(db *migro.DB, table string) *Builder

Table starts a query on a table.

func (*Builder) Count

func (b *Builder) Count(ctx context.Context) (int64, error)

func (*Builder) Delete

func (b *Builder) Delete(ctx context.Context) (int64, error)

Delete removes matching rows. Without a Where, GORM refuses and an error is returned.

func (*Builder) First

func (b *Builder) First(ctx context.Context) (Row, error)

First returns the first matching row or migro.ErrNotFound.

func (*Builder) Get

func (b *Builder) Get(ctx context.Context) ([]Row, error)

Get returns all matching rows.

func (*Builder) GroupBy

func (b *Builder) GroupBy(cols ...string) *Builder

func (*Builder) Having

func (b *Builder) Having(query any, args ...any) *Builder

func (*Builder) Insert

func (b *Builder) Insert(ctx context.Context, rows ...Row) error

Insert inserts one or more rows.

func (*Builder) Join

func (b *Builder) Join(clause string, args ...any) *Builder

Join takes a raw clause such as "JOIN posts ON posts.user_id = users.id".

func (*Builder) Limit

func (b *Builder) Limit(n int) *Builder

func (*Builder) Not

func (b *Builder) Not(query any, args ...any) *Builder

func (*Builder) Offset

func (b *Builder) Offset(n int) *Builder

func (*Builder) OrWhere

func (b *Builder) OrWhere(query any, args ...any) *Builder

func (*Builder) OrderBy

func (b *Builder) OrderBy(col, dir string) *Builder

OrderBy sorts by col; dir is "asc" or "desc" (anything else is rejected at execution).

func (*Builder) Paginate

func (b *Builder) Paginate(ctx context.Context, page, perPage int) (Page, error)

Paginate runs a count and a page query. page starts at 1.

func (*Builder) Pluck

func (b *Builder) Pluck(ctx context.Context, col string) ([]any, error)

Pluck returns a single column as []any.

func (*Builder) Select

func (b *Builder) Select(cols ...string) *Builder

func (*Builder) String

func (b *Builder) String() string

func (*Builder) Update

func (b *Builder) Update(ctx context.Context, values Row) (int64, error)

Update sets columns on matching rows and returns the affected count. Without a Where, GORM refuses and an error is returned.

func (*Builder) Where

func (b *Builder) Where(query any, args ...any) *Builder

Where accepts a SQL fragment with ? placeholders ("age > ?", 18) or a map[string]any. Values are always bound, never interpolated.

func (*Builder) WhereBetween

func (b *Builder) WhereBetween(col string, lo, hi any) *Builder

func (*Builder) WhereIn

func (b *Builder) WhereIn(col string, values any) *Builder

WhereIn binds values; column is quoted by the dialect.

func (*Builder) WhereNotNull

func (b *Builder) WhereNotNull(col string) *Builder

func (*Builder) WhereNull

func (b *Builder) WhereNull(col string) *Builder

type Page

type Page struct {
	Data        []Row
	Total       int64
	PerPage     int
	CurrentPage int
	LastPage    int
}

Page is one page of results.

type Row

type Row = map[string]any

Jump to

Keyboard shortcuts

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