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 ¶
- func New(cfg dict.Config) (dict.Dict, error)
- type Dict
- func (d *Dict) Begin(ctx context.Context, set *dict.OpSettings) (dict.Tx, error)
- func (d *Dict) Close() error
- func (d *Dict) ExpireScan(ctx context.Context) error
- func (d *Dict) Iterate(ctx context.Context, set *dict.OpSettings, path string, flags dict.IterFlag) (dict.Iterator, error)
- func (d *Dict) Lookup(ctx context.Context, set *dict.OpSettings, key string) ([][]byte, bool, error)
- func (d *Dict) Name() string
- func (d *Dict) Wait(_ context.Context) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
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) ExpireScan ¶
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.