From d04ef88c0c531de681ca00bb2a577cfb88269719 Mon Sep 17 00:00:00 2001 From: Virgil Date: Thu, 19 Feb 2026 16:20:30 +0000 Subject: [PATCH] Add "Home" --- Home.md | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 Home.md diff --git a/Home.md b/Home.md new file mode 100644 index 0000000..aead110 --- /dev/null +++ b/Home.md @@ -0,0 +1,91 @@ +# go-store + +A lightweight SQLite key-value store with group namespacing and built-in Go template rendering. Designed for configuration, state, and small-data persistence where a full ORM is overkill. + +## Installation + +```bash +go get forge.lthn.ai/core/go-store +``` + +## Features + +- **Group-namespaced keys** — logical separation without multiple tables +- **SQLite WAL mode** — concurrent reads, safe writes +- **Upsert semantics** — `Set` creates or overwrites automatically +- **Template rendering** — load a group into a Go template in one call +- **In-memory mode** — use `":memory:"` for tests +- **Pure Go SQLite** — via `modernc.org/sqlite` (no CGO required) + +## Quick Example + +```go +package main + +import ( + "fmt" + "log" + + "forge.lthn.ai/core/go-store" +) + +func main() { + s, err := store.New("app.db") + if err != nil { + log.Fatal(err) + } + defer s.Close() + + // Store configuration values + s.Set("config", "theme", "dark") + s.Set("config", "lang", "en-GB") + s.Set("config", "timezone", "Europe/London") + + // Retrieve a single value + theme, _ := s.Get("config", "theme") + fmt.Println(theme) // "dark" + + // Count keys in a group + n, _ := s.Count("config") + fmt.Printf("%d config keys +", n) // "3 config keys" + + // Render a template using group values + tmpl := `Theme: {{ .theme }}, Language: {{ .lang }}` + out, _ := s.Render(tmpl, "config") + fmt.Println(out) // "Theme: dark, Language: en-GB" +} +``` + +## Schema + +The store uses a single `kv` table with a composite primary key: + +```sql +CREATE TABLE IF NOT EXISTS kv ( + grp TEXT NOT NULL, + key TEXT NOT NULL, + value TEXT NOT NULL, + PRIMARY KEY (grp, key) +); +``` + +``` +┌──────────────────────────────────────────┐ +│ kv │ +├──────────┬──────────┬────────────────────┤ +│ grp (PK) │ key (PK) │ value │ +├──────────┼──────────┼────────────────────┤ +│ config │ theme │ dark │ +│ config │ lang │ en-GB │ +│ user │ pool │ pool.lthn.io:3333 │ +│ user │ wallet │ iz... │ +└──────────┴──────────┴────────────────────┘ +``` + +Groups provide logical namespacing — you can have the same key in different groups without conflict. All group operations (`GetAll`, `DeleteGroup`, `Count`, `Render`) scope to a single group. + +## Pages + +- [[API-Reference]] — Full method documentation with signatures and error handling +- [[Template-Rendering]] — Go template syntax, Render method, practical examples