Skip to content

Instantly share code, notes, and snippets.

@araddon
Last active August 29, 2015 14:21
Show Gist options
  • Save araddon/0c9364db3314a61cea2d to your computer and use it in GitHub Desktop.
Save araddon/0c9364db3314a61cea2d to your computer and use it in GitHub Desktop.
forestdb
package main
import (
"fmt"
u "github.com/araddon/gou"
forestdb "github.com/couchbaselabs/goforestdb"
)
func main() {
u.SetupLogging("debug")
u.SetColorIfTerminal()
// Open a database
config := forestdb.DefaultConfig()
u.Infof("durability:%T:%v", config.DurabilityOpt(), config.DurabilityOpt())
config.SetDurabilityOpt(forestdb.DRB_ODIRECT)
db, err := forestdb.Open("test", config)
if err != nil {
panic(err)
}
dbinfo, _ := db.Info()
u.Infof("DB Info: %#v docct:%v", dbinfo, dbinfo.DocCount())
kvstore, err := db.OpenKVStoreDefault(forestdb.DefaultKVStoreConfig())
if err != nil {
panic(err)
}
// Close it properly when we're done
defer func() {
// Try commenting/uncommenting this line
db.Commit(forestdb.COMMIT_MANUAL_WAL_FLUSH)
kvstore.Close()
db.Close()
}()
info, _ := db.Info()
u.Infof("Info: %#v docct:%v", info, info.DocCount())
iter, err := kvstore.IteratorInit([]byte("00000000"), []byte("00000500"), forestdb.ITR_NONE)
if err != nil {
u.Errorf("Could not setup iterator: %v", err)
return
}
defer iter.Close()
doc, err := iter.Get()
if err != nil {
u.Errorf("Could not iter.Get(): %v", err)
//return
}
count := 0
var firstKey, lastKey []byte
for err == nil {
count++
//u.Debugf("for: %v ct:%v", string(doc.Key()), count)
if firstKey == nil {
firstKey = doc.Key()
}
lastKey = doc.Key()
doc.Close()
err = iter.Next()
if err == nil {
doc, err = iter.Get()
}
}
if count != 500 {
u.Errorf("expected to find 500 items but go %v lastKey:%v", count, lastKey)
} else {
u.Infof("Found 500 keys we were looking for!")
}
// Write 1000 data rows
for i := 1; i <= 1000; i++ {
keystr := fmt.Sprintf("%08d", i)
key := []byte(keystr)
// Store the document
//u.Infof("key: %s", key)
kvstore.SetKV(key, key)
}
}
@epsniff
Copy link

epsniff commented May 27, 2015

https://github.com/couchbase/goforestdb/blob/master/config.go#L90 -- Lots and lots of config options.... :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment