sql

package
v2.4.5 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

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

Three drivers, selected via Config.Settings, all statically compiled in:

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

Generic KV 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; it lets multiple features share one database without key collisions.

Multi-value is not stored: a second Set on the same key overwrites. AtomicInc reports CommitNotFound when the key is absent.

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" | "mysql" (required)
"dsn"        string - go-database/sql DSN (required)
"table"      string - table name; default "dict_kv"
"namespace"  string - per-Dict prefix; default ""
"maps"       list   - enables mapped mode (see below); optional

Generic KV mode auto-creates the table on Open (IF NOT EXISTS, idempotent).

Mapped mode (when "maps" is present): each dict key binds to a table column, so a per-user row carries one column per key (username_field is the primary key). The operator owns the schema, so no auto-create runs. Each map entry is:

{ key: "priv/quota/storage", table: quota, username_field: username, value_field: bytes }

Types

type Dict

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

Dict is the database/sql driver.

func (*Dict) Begin

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

Begin implements dict.Dict.

func (*Dict) Close

func (d *Dict) Close() error

Close implements dict.Dict.

func (*Dict) ExpireScan

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

ExpireScan implements dict.Dict.

func (*Dict) Iterate

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

Iterate implements dict.Dict.

func (*Dict) Lookup

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

Lookup implements dict.Dict.

func (*Dict) Name

func (d *Dict) Name() string

Name implements dict.Dict.

func (*Dict) Wait

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

Wait implements dict.Dict.

Jump to

Keyboard shortcuts

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