initial commit
This commit is contained in:
commit
18995db757
871 changed files with 492725 additions and 0 deletions
63
pkg/db/db.go
Normal file
63
pkg/db/db.go
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
// Copyright (C) 2019 Marius Schellenberger
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"git.giftfish.de/ston1th/docstore/pkg/core"
|
||||
"git.giftfish.de/ston1th/docstore/pkg/index"
|
||||
"git.giftfish.de/ston1th/docstore/pkg/store"
|
||||
"git.giftfish.de/ston1th/godrop/v2"
|
||||
"io"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
const (
|
||||
storeFile = "store.db"
|
||||
bcryptCost = 13
|
||||
)
|
||||
|
||||
const blevePath = "bleve"
|
||||
|
||||
type DB struct {
|
||||
store store.Store
|
||||
Index *index.Index
|
||||
}
|
||||
|
||||
func New(cfg core.Config) (db *DB, err error) {
|
||||
db = new(DB)
|
||||
dbFile := filepath.Join(cfg.DataDir, storeFile)
|
||||
err = godrop.Unveil(dbFile, "rwc")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
db.store, err = store.NewBoltStore(dbFile, nil)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
db.Index, err = index.NewIndex(filepath.Join(cfg.DataDir, blevePath))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = db.UnlockUser()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = db.RunMigrations()
|
||||
return
|
||||
}
|
||||
|
||||
func (db *DB) Dump(w io.Writer) error {
|
||||
return db.store.Dump(w)
|
||||
}
|
||||
|
||||
func (db *DB) Restore(r io.Reader) error {
|
||||
return db.store.Restore(r)
|
||||
}
|
||||
|
||||
func (db *DB) Close() (err error) {
|
||||
err = db.store.Close()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return db.Index.Close()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue