Make db name-literal agnostic
Move the persistence characteristic of the store into the graph registry and provide an API hook to get that information. Add error return for init on a non-persistent store. Updates #35.
This commit is contained in:
parent
7cd740aa7b
commit
2d4c07b56d
7 changed files with 36 additions and 21 deletions
|
|
@ -15,11 +15,20 @@
|
|||
package db
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/google/cayley/config"
|
||||
"github.com/google/cayley/graph"
|
||||
)
|
||||
|
||||
var ErrNotPersistent = errors.New("database type is not persistent")
|
||||
|
||||
func Init(cfg *config.Config, triplePath string) error {
|
||||
if !graph.IsPersistent(cfg.DatabaseType) {
|
||||
return fmt.Errorf("ignoring unproductive database initialization request: %v", ErrNotPersistent)
|
||||
}
|
||||
|
||||
err := graph.InitTripleStore(cfg.DatabaseType, cfg.DatabasePath, cfg.DatabaseOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@ func Open(cfg *config.Config) (graph.TripleStore, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// Memstore is not persistent, so it MUST be loaded.
|
||||
if cfg.DatabaseType == "memstore" {
|
||||
if !graph.IsPersistent(cfg.DatabaseType) {
|
||||
err = Load(ts, cfg, cfg.DatabasePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue