In-Memory Store (gomap)
Fast in-memory store using Go maps.
Zestor provides multiple store implementations, all sharing the same store.Store[T] interface. This means you can swap implementations without changing your application code.
| Implementation | Storage | Persistence | Best For |
|---|---|---|---|
| gomap | Memory | ❌ Ephemeral | Caching, testing, high-speed access |
| sqlite | SQLite file | ✅ Persistent | Desktop apps, CLI tools, embedded |
All implementations satisfy store.Store[T]:
// Works with any implementation
func processUsers(s store.Store[User]) error {
users, err := s.List("users")
// ...
}
// In-memory
memStore := gomap.NewMemStore[User](opts)
processUsers(memStore)
// SQLite
sqlStore, _ := sqlite.New[User](sqlOpts)
processUsers(sqlStore)
A common pattern is using gomap for tests and sqlite for production:
func NewStore(cfg Config) (store.Store[User], error) {
if cfg.Testing {
return gomap.NewMemStore[User](store.StoreOptions[User]{}), nil
}
return sqlite.New[User](sqlite.Options{
DSN: cfg.DatabasePath,
Codec: &codec.JSON{},
})
}
| Feature | gomap | sqlite |
|---|---|---|
| Thread-safe | ✅ | ✅ |
| Watch/Subscribe | ✅ | ✅ (in-process) |
| Validation hooks | ✅ | ❌ |
| Compare function | ✅ | ❌ (byte comparison) |
| Persistence | ❌ | ✅ |
| Version tracking | ❌ | ✅ |
| Transactions | ❌ | ✅ |
| Cross-process watch | ❌ | ❌ |
Future implementations may include:
Fast in-memory store using Go maps.
Persistent store backed by SQLite database.