diff --git a/cli/defradb/cmd/start.go b/cli/defradb/cmd/start.go index 7c672dbef5..7dccd71a4d 100644 --- a/cli/defradb/cmd/start.go +++ b/cli/defradb/cmd/start.go @@ -35,10 +35,12 @@ 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) @@ -46,9 +48,10 @@ var startCmd = &cobra.Command{ } 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) diff --git a/db/db.go b/db/db.go index 6a173c66dd..e116a3105f 100644 --- a/db/db.go +++ b/db/db.go @@ -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) @@ -123,6 +126,7 @@ func NewDB(rootstore ds.Batching) (*DB, error) { schema: sm, queryExecutor: exec, + options: options, } return db, err diff --git a/db/db_test.go b/db/db_test.go index 5fb9e2385a..4ddcb3cd10 100644 --- a/db/db_test.go +++ b/db/db_test.go @@ -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) { @@ -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) } @@ -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) } diff --git a/db/tests/utils.go b/db/tests/utils.go index 66265cd18d..80889f1141 100644 --- a/db/tests/utils.go +++ b/db/tests/utils.go @@ -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) {