mirror of
https://github.com/safing/portbase
synced 2026-05-01 05:09:59 +00:00
Work on database revamp [WIP]
This commit is contained in:
parent
307ddd70fd
commit
efabb291d7
19 changed files with 1032 additions and 664 deletions
|
|
@ -9,29 +9,20 @@ import (
|
|||
"path"
|
||||
"strings"
|
||||
|
||||
ds "github.com/ipfs/go-datastore"
|
||||
dsq "github.com/ipfs/go-datastore/query"
|
||||
mount "github.com/ipfs/go-datastore/syncmount"
|
||||
|
||||
"github.com/Safing/safing-core/database/dbutils"
|
||||
"github.com/Safing/safing-core/database/ds/channelshim"
|
||||
"github.com/Safing/safing-core/database/ds/leveldb"
|
||||
"github.com/Safing/safing-core/log"
|
||||
"github.com/Safing/safing-core/meta"
|
||||
)
|
||||
|
||||
// TODO: do not let other modules panic, even if database module crashes.
|
||||
var db ds.Datastore
|
||||
|
||||
var ErrNotFound = errors.New("database: entry could not be found")
|
||||
|
||||
func init() {
|
||||
if strings.HasSuffix(os.Args[0], ".test") {
|
||||
// testing setup
|
||||
log.Warning("===== DATABASE RUNNING IN TEST MODE =====")
|
||||
db = channelshim.NewChanneledDatastore(ds.NewMapDatastore())
|
||||
return
|
||||
}
|
||||
// if strings.HasSuffix(os.Args[0], ".test") {
|
||||
// // testing setup
|
||||
// log.Warning("===== DATABASE RUNNING IN TEST MODE =====")
|
||||
// db = channelshim.NewChanneledDatastore(ds.NewMapDatastore())
|
||||
// return
|
||||
// }
|
||||
|
||||
// sfsDB, err := simplefs.NewDatastore(meta.DatabaseDir())
|
||||
// if err != nil {
|
||||
|
|
@ -39,24 +30,24 @@ func init() {
|
|||
// os.Exit(1)
|
||||
// }
|
||||
|
||||
ldb, err := leveldb.NewDatastore(path.Join(meta.DatabaseDir(), "leveldb"), &leveldb.Options{})
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "FATAL ERROR: could not init simplefs database: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
mapDB := ds.NewMapDatastore()
|
||||
|
||||
db = channelshim.NewChanneledDatastore(mount.New([]mount.Mount{
|
||||
mount.Mount{
|
||||
Prefix: ds.NewKey("/Run"),
|
||||
Datastore: mapDB,
|
||||
},
|
||||
mount.Mount{
|
||||
Prefix: ds.NewKey("/"),
|
||||
Datastore: ldb,
|
||||
},
|
||||
}))
|
||||
// ldb, err := leveldb.NewDatastore(path.Join(meta.DatabaseDir(), "leveldb"), &leveldb.Options{})
|
||||
// if err != nil {
|
||||
// fmt.Fprintf(os.Stderr, "FATAL ERROR: could not init simplefs database: %s\n", err)
|
||||
// os.Exit(1)
|
||||
// }
|
||||
//
|
||||
// mapDB := ds.NewMapDatastore()
|
||||
//
|
||||
// db = channelshim.NewChanneledDatastore(mount.New([]mount.Mount{
|
||||
// mount.Mount{
|
||||
// Prefix: ds.NewKey("/Run"),
|
||||
// Datastore: mapDB,
|
||||
// },
|
||||
// mount.Mount{
|
||||
// Prefix: ds.NewKey("/"),
|
||||
// Datastore: ldb,
|
||||
// },
|
||||
// }))
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue