Closed dstpierre closed 1 year ago
The addition of sqlite
as a data provider made this extremely simple.
The cli
will have a new flag --persist-data
which will use sqlite
instead of the memory data provider and will persist data without any more changes.
This will be available in the v1.5
release.
In development mode the CLI uses the
memory
database provider, making everything versatile.It could be helpful to have an option to save the memory database from a flag on the CLI
server
command.Overview for this change
In the core package:
Two function could be added to the
memory/memory.go
file to load and save the database.The
Memory
type inmemory.go:31
contains amap[string]map[string][]byte
(ho yeah, I did that). This is basically what's used as the in-memory database.The two new functions in this file could be
(m *Memory) Load(filename string) error
and(m *Memory) Save(filename string) error
. We could usegob
to encode/decode thisDB
to the file.Ideally, I'd not want to have the
Persister
interface to have those two function. Maybe we could create a new interface with those 2 and check when it's time to call those function if the runtime implementation has those (pseudo code):p.s. writing this makes me wonder if the
Memory
type could not juste implementio.Reader
andio.Writer
instead of having our own interface.Nonetheless, somewhere would be this:
in the cli program:
server.go
file add a command parameter (like the Port), say "filename"server.go
when the DB is instanciated we could have theLoad
andSave
(from a defer called.This is an idea of how this could be implemented. Open to any suggestion, do not hesitate to speak your idea/suggestion in here.