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