Packages
Search packages... ⌘K
Go Package
dictionary
Two-tier dictionary sync — YAML-defined enumerations with database sync
Go Ready MD
Dictionary Definition and Sync go
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Define enumerations in YAML, load into typed dictionaries
statuses := dictionary.Dictionary{
Name: "project_status",
Table: "lookup_project_status",
Entries: []dictionary.Entry{
{Code: "draft", Label: "Draft", Order: 1},
{Code: "active", Label: "Active", Order: 2},
{Code: "archived", Label: "Archived", Order: 3},
},
}
// Sync to database — inserts new, updates changed, preserves extras
err := dictionary.Sync(ctx, pool, statuses)
// Fast in-memory lookup
entry, ok := statuses.Lookup("active")
// entry.Label == "Active"About
Manages enumeration values defined in YAML files and synchronized to database lookup tables. Supports two-tier resolution: fast in-memory lookup from YAML with database as the authoritative store for runtime additions.
Public API
| Name | Kind | Signature |
|---|---|---|
| Dictionary | type | type Dictionary struct |
| Entry | type | type Entry struct |
| Sync | func | func Sync(ctx context.Context, pool *database.Pool, dicts ...Dictionary) error |
| Lookup | func | func (d *Dictionary) Lookup(code string) (*Entry, bool) |
Dependencies
Related Packages
Source
github.com/shredbx/sbx-core/pkg/dictionary
enumerationslookup-tablesyaml-synctwo-tier