linkwallet/db/db.go

36 lines
620 B
Go
Raw Permalink Normal View History

2022-05-24 18:03:31 +09:30
package db
import (
"fmt"
2022-05-24 18:03:31 +09:30
"log"
"github.com/tardisx/linkwallet/entity"
bolthold "github.com/timshannon/bolthold"
2022-05-24 18:03:31 +09:30
)
type DB struct {
store *bolthold.Store
2022-05-24 18:03:31 +09:30
}
func (db *DB) Open(path string) error {
// options := bolthold.DefaultOptions
// options.Dir = dir
// options.ValueDir = dir
store, err := bolthold.Open(path, 0666, nil)
2022-05-24 18:03:31 +09:30
if err != nil {
return fmt.Errorf("cannot open '%s' - %s", path, err)
2022-05-24 18:03:31 +09:30
}
db.store = store
return nil
2022-05-24 18:03:31 +09:30
}
func (db *DB) Close() {
db.store.Close()
}
func (db *DB) Dumpy() {
res := make([]entity.Bookmark, 0, 0)
db.store.Find(&res, &bolthold.Query{})
2022-05-24 18:03:31 +09:30
log.Printf("%v", res)
}