Key-Value store in Progress
$ go get github.com/saromanov/lightstore/...
Easy steps for create a new database
package main
import "github.com/saromanov/lightstore/store"
func main() {
light, err := store.Open(nil)
if err != nil {
panic(err)
}
defer light.Close()
}
This creates a new database with default config
Or create database only with path to db file
light, err := store.OpenStrict("db.db")
if err != nil {
panic(err)
}
defer light.Close()
For make new transaction, need to open new transaction and then commit changes
err = light.Write(func(txn *store.Txn) error {
for i := 0; i < 20; i++ {
err := txn.Set([]byte(fmt.Sprintf("%d", i)), []byte(fmt.Sprintf("bar+%d", i)))
if err != nil {
return err
}
}
return txn.Commit()
})
if err != nil {
log.Fatalf("unable to write data: %v", err)
}
light.View(func(txn *store.Txn) error {
it, _ := txn.NewIterator(store.IteratorOptions{})
for it.First(); it.Valid(); it.Next() {
itm := it.Item()
fmt.Println(string(itm.Key()), string(itm.Value()))
}
return nil
})