3 // persistent key-value store
4 // multiple key-value store can be managed by a single db connection
5 // each store has a name, before usage the name of the store must be
8 // TODO: this is a toy implementation
21 func Open(root string) (c *Conn, err error) {
23 c.path, err = filepath.Abs(root)
27 err = os.MkdirAll(c.path, 0755)
34 func (c *Conn) Get(name, k string) (v []byte, err error) {
35 return ioutil.ReadFile(filepath.Join(c.path, name, k))
38 func (c *Conn) Ensure(name string) (err error) {
39 return os.MkdirAll(filepath.Join(c.path, name), 0755)
42 func (c *Conn) Set(name, k string, v []byte) (err error) {
43 fn := filepath.Join(c.path, name, k)
45 f, err := os.Create(fn+".tmp")
54 err = os.Rename(fn+".tmp", fn)
58 func (c *Conn) Close() (err error) {