d574a3af6d
This commit contains the entire btcdb repository along with several changes needed to move all of the files into the database directory in order to prepare it for merging. This does NOT update btcd or any of the other packages to use the new location as that will be done separately. - All import paths in the old btcdb test files have been changed to the new location - All references to btcdb as the package name have been chagned to database - The coveralls badge has been removed since it unfortunately doesn't support coverage of sub-packages This is ongoing work toward #214.
58 lines
1 KiB
Go
58 lines
1 KiB
Go
//
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/btcsuite/goleveldb/leveldb"
|
|
"github.com/btcsuite/goleveldb/leveldb/opt"
|
|
)
|
|
|
|
type tst struct {
|
|
key int
|
|
value string
|
|
}
|
|
|
|
var dataset = []tst{
|
|
//var dataset = []struct { key int, value string } {
|
|
{1, "one"},
|
|
{2, "two"},
|
|
{3, "three"},
|
|
{4, "four"},
|
|
{5, "five"},
|
|
}
|
|
|
|
func main() {
|
|
|
|
ro := &opt.ReadOptions{}
|
|
wo := &opt.WriteOptions{}
|
|
opts := &opt.Options{}
|
|
|
|
ldb, err := leveldb.OpenFile("dbfile", opts)
|
|
if err != nil {
|
|
fmt.Printf("db open failed %v\n", err)
|
|
return
|
|
}
|
|
|
|
batch := new(leveldb.Batch)
|
|
for _, datum := range dataset {
|
|
key := fmt.Sprintf("%v", datum.key)
|
|
batch.Put([]byte(key), []byte(datum.value))
|
|
}
|
|
err = ldb.Write(batch, wo)
|
|
|
|
for _, datum := range dataset {
|
|
key := fmt.Sprintf("%v", datum.key)
|
|
data, err := ldb.Get([]byte(key), ro)
|
|
|
|
if err != nil {
|
|
fmt.Printf("db read failed %v\n", err)
|
|
}
|
|
|
|
if string(data) != datum.value {
|
|
fmt.Printf("mismatched data from db key %v val %v db %v", key, datum.value, data)
|
|
}
|
|
}
|
|
fmt.Printf("completed\n")
|
|
ldb.Close()
|
|
}
|