Help us shape the future of Go! Take the 2026 Go Developer Survey

sqlite

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package sqlite links the pure-Go SQLite engine (glebarez/go-sqlite, on modernc's) for the ORM: blank-import it to Connect to "sqlite".

import _ "github.com/vuka-lang/orm/sqlite"

db, err := orm.Connect("sqlite", "file:shop.db?_pragma=busy_timeout(5000)&_pragma=journal_mode(WAL)")

Kept out of the orm package itself so a Postgres or MySQL program doesn't ship the transpiled-C SQLite engine (~5MB of binary) it never opens. Don't import it beside another package registering the "sqlite" database/sql driver (modernc.org/sqlite).

It also gives SQLite the functions Postgres's pgvector and pg_trgm have, computed in Go, unindexed: l2_distance, cosine_distance and inner_product of vectors written as text ([1,2,3]), and similarity, the trigram similarity of two texts. The ORM's vector and trigram searches use them, so they run on SQLite in development and tests.

Func registers a Go function of your own the same way, for an orm.Func to call.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Func

func Func(name string, fn any, opts ...Option) error

Func registers fn, a Go function, as the SQL function name on every SQLite connection opened after it — so register in an init, or before orm.Connect: connections already open don't get it. It is deterministic unless Volatile.

fn's parameters are its SQL arguments, its last one variadic or not: string, []byte, bool, the integer and float kinds, time.Time (read from SQLite's text), any (what SQLite has: int64, float64, string, []byte or nil), or a pointer to one of them, nil for NULL. A NULL passed to a parameter that isn't a pointer or any makes the call NULL without running fn, as SQL's own functions are. It returns one value of those kinds (a driver.Valuer too, a nil pointer for NULL), and an error after it if it can fail.

func init() {
	sqlite.MustFunc("editdist", func(a, b string) int { … })
}
var EditDist = orm.OrderedFunc[int]("editdist",
	orm.Template("sqlite", "editdist({0}, {1})"), orm.Template("postgres", "levenshtein({0}, {1})"))

Users.Filter(EditDist(orm.F("name"), "jon").Le(1)).Order(EditDist(orm.F("name"), "jon").Asc())

Postgres and MySQL run functions written in SQL: create them with the migration package's CreateFunction, and give the orm function a Template per dialect when the names differ.

func MustFunc

func MustFunc(name string, fn any, opts ...Option)

MustFunc is Func, panicking on its error.

Types

type Option

type Option func(*funcOptions)

Option shapes a Func.

func Volatile

func Volatile() Option

Volatile registers a function whose result may differ for the same arguments (a clock, a random number): SQLite won't index it or fold its calls.

Jump to

Keyboard shortcuts

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