Skip to content

Commit

Permalink
FIXUP - add options back onto db struct using interface
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSisley committed Nov 22, 2021
1 parent b849fb8 commit 735e9eb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
5 changes: 4 additions & 1 deletion cli/defradb/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,23 @@ var startCmd = &cobra.Command{
signal.Notify(signalCh, os.Interrupt)

var rootstore ds.Batching
var options interface{}
var err error
if config.Database.Store == "badger" {
log.Info("opening badger store: ", config.Database.Badger.Path)
rootstore, err = badgerds.NewDatastore(config.Database.Badger.Path, config.Database.Badger.Options)
options = config.Database.Badger
if err != nil {
log.Error("Failed to initiate database:", err)
os.Exit(1)
}
} else if config.Database.Store == "memory" {
log.Info("building new memory store")
rootstore = ds.NewMapDatastore()
options = config.Database.Memory
}

db, err := db.NewDB(rootstore)
db, err := db.NewDB(rootstore, options)
if err != nil {
log.Error("Failed to initiate database:", err)
os.Exit(1)
Expand Down
6 changes: 5 additions & 1 deletion db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,13 @@ type DB struct {
initialized bool

log logging.StandardLogger

// The options used to init the database
options interface{}
}

// NewDB creates a new instance of the DB using the given options
func NewDB(rootstore ds.Batching) (*DB, error) {
func NewDB(rootstore ds.Batching, options interface{}) (*DB, error) {
log.Debug("loading: internal datastores")
systemstore := namespace.Wrap(rootstore, systemStoreKey)
datastore := namespace.Wrap(rootstore, dataStoreKey)
Expand Down Expand Up @@ -123,6 +126,7 @@ func NewDB(rootstore ds.Batching) (*DB, error) {

schema: sm,
queryExecutor: exec,
options: options,
}

return db, err
Expand Down
6 changes: 3 additions & 3 deletions db/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

func newMemoryDB() (*DB, error) {
rootstore := ds.NewMapDatastore()
return NewDB(rootstore)
return NewDB(rootstore, struct{}{})
}

func newTestCollection(ctx context.Context, db *DB) (*Collection, error) {
Expand All @@ -41,7 +41,7 @@ func newTestCollection(ctx context.Context, db *DB) (*Collection, error) {
func TestNewDB(t *testing.T) {
rootstore := ds.NewMapDatastore()

_, err := NewDB(rootstore)
_, err := NewDB(rootstore, struct{}{})
if err != nil {
t.Error(err)
}
Expand All @@ -51,7 +51,7 @@ func TestNewDBWithCollection_Errors_GivenNoSchema(t *testing.T) {
ctx := context.Background()
rootstore := ds.NewMapDatastore()

db, err := NewDB(rootstore)
db, err := NewDB(rootstore, struct{}{})
if err != nil {
t.Error(err)
}
Expand Down
2 changes: 1 addition & 1 deletion db/tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type QueryTestCase struct {

func NewMemoryDB() (*db.DB, error) {
rootstore := ds.NewMapDatastore()
return db.NewDB(rootstore)
return db.NewDB(rootstore, struct{}{})
}

func ExecuteQueryTestCase(t *testing.T, schema string, collectionNames []string, test QueryTestCase) {
Expand Down

0 comments on commit 735e9eb

Please sign in to comment.