Skip to content

Commit 149e1c7

Browse files
committed
graph/db: add StoreOptions to NewSQLStore
1 parent a0a20bd commit 149e1c7

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

graph/db/sql_store.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package graphdb
22

33
import (
4+
"fmt"
5+
46
"github.com/lightningnetwork/lnd/sqldb"
57
)
68

@@ -37,9 +39,21 @@ var _ V1Store = (*SQLStore)(nil)
3739

3840
// NewSQLStore creates a new SQLStore instance given an open BatchedSQLQueries
3941
// storage backend.
40-
func NewSQLStore(db BatchedSQLQueries, kvStore *KVStore) *SQLStore {
42+
func NewSQLStore(db BatchedSQLQueries, kvStore *KVStore,
43+
options ...StoreOptionModifier) (*SQLStore, error) {
44+
45+
opts := DefaultOptions()
46+
for _, o := range options {
47+
o(opts)
48+
}
49+
50+
if opts.NoMigration {
51+
return nil, fmt.Errorf("the NoMigration option is not yet " +
52+
"supported for SQL stores")
53+
}
54+
4155
return &SQLStore{
4256
db: db,
4357
KVStore: kvStore,
44-
}
58+
}, nil
4559
}

graph/db/test_postgres.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,8 @@ func NewTestDB(t testing.TB) V1Store {
3838
},
3939
)
4040

41-
return NewSQLStore(executor, graphStore)
41+
store, err := NewSQLStore(executor, graphStore)
42+
require.NoError(t, err)
43+
44+
return store
4245
}

graph/db/test_sqlite.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,8 @@ func NewTestDB(t testing.TB) V1Store {
3131
},
3232
)
3333

34-
return NewSQLStore(executor, graphStore)
34+
store, err := NewSQLStore(executor, graphStore)
35+
require.NoError(t, err)
36+
37+
return store
3538
}

0 commit comments

Comments
 (0)