move to registry interface for backends

This commit is contained in:
Jeremy Jay 2014-07-16 16:49:55 -04:00
parent e780c1ceb9
commit d808d9347c
9 changed files with 117 additions and 64 deletions

View file

@ -16,25 +16,19 @@ package db
import (
"github.com/google/cayley/config"
"github.com/google/cayley/graph/leveldb"
"github.com/google/cayley/graph/mongo"
"github.com/google/cayley/graph"
)
func Init(cfg *config.Config, triplePath string) bool {
created := false
dbpath := cfg.DatabasePath
switch cfg.DatabaseType {
case "mongo", "mongodb":
created = mongo.CreateNewMongoGraph(dbpath, cfg.DatabaseOptions)
case "leveldb":
created = leveldb.CreateNewLevelDB(dbpath)
case "mem":
return true
err := graph.InitTripleStore(cfg.DatabaseType, cfg.DatabasePath, cfg.DatabaseOptions)
if err != nil {
return false
}
if created && triplePath != "" {
if triplePath != "" {
ts := Open(cfg)
Load(ts, cfg, triplePath, true)
Load(ts, cfg, triplePath)
ts.Close()
}
return created
return true
}