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

sql

package
v1.99.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package sql is a database/sql-backed dict driver.

Supports two drivers out of the box, selected via Config.Settings:

driver: "sqlite"   — modernc.org/sqlite (pure Go, no CGO)
driver: "postgres" — github.com/jackc/pgx/v5/stdlib (pure Go)

Both are statically compiled in so the choice is runtime-config-only, per yarilo's config-not-binary rule.

Schema:

CREATE TABLE <table> (
    namespace TEXT NOT NULL,
    k         TEXT NOT NULL,
    v         BLOB NOT NULL,
    expires   BIGINT,                -- unix seconds; NULL = no TTL
    PRIMARY KEY (namespace, k)
);
CREATE INDEX <table>_expires_idx ON <table>(expires) WHERE expires IS NOT NULL;

"namespace" is the per-Dict prefix (matches Redis driver's prefix concept) — lets multiple yarilo features share one database without key collisions. ExpireScan runs `DELETE FROM <table> WHERE expires IS NOT NULL AND expires <= ?` and reports the row count via the driver's slog logger.

Multi-value: not stored. A second Set on the same key overwrites. Use SQL directly for any feature that genuinely needs multi-value.

Transactions: native database/sql transactions. AtomicInc uses UPDATE ... SET v = CAST(CAST(v AS BIGINT) + ? AS BLOB) WHERE k=? and reports CommitNotFound when zero rows were affected.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(cfg dict.Config) (dict.Dict, error)

New constructs an sql dict. Recognised settings:

"driver"     string — "sqlite" | "postgres" (required)
"dsn"        string — go-database/sql DSN (required)
"table"      string — table name; default "dict_kv"
"namespace"  string — per-Dict prefix; default ""

The table is auto-created on Open if it does not exist. To opt out of auto-create (e.g. when the schema is managed by a migration tool), pre-create the table; the IF NOT EXISTS guard is idempotent.

Types

type Dict

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

func (*Dict) Begin

func (d *Dict) Begin(ctx context.Context, set *dict.OpSettings) (dict.Tx, error)

func (*Dict) Close

func (d *Dict) Close() error

func (*Dict) ExpireScan

func (d *Dict) ExpireScan(ctx context.Context) error

func (*Dict) Iterate

func (d *Dict) Iterate(ctx context.Context, _ *dict.OpSettings, path string, flags dict.IterFlag) (dict.Iterator, error)

func (*Dict) Lookup

func (d *Dict) Lookup(ctx context.Context, _ *dict.OpSettings, key string) ([][]byte, bool, error)

func (*Dict) Name

func (d *Dict) Name() string

func (*Dict) Wait

func (d *Dict) Wait(_ context.Context) error

Jump to

Keyboard shortcuts

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