Add "Home"

Virgil 2026-02-19 16:20:30 +00:00
parent 9cdc36a50f
commit d04ef88c0c

91
Home.md Normal file

@ -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