From 149e1c7d355b31a4a6a838cf108cb0db53ceb083 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Fri, 23 May 2025 11:00:29 +0200 Subject: [PATCH] graph/db: add StoreOptions to NewSQLStore --- graph/db/sql_store.go | 18 ++++++++++++++++-- graph/db/test_postgres.go | 5 ++++- graph/db/test_sqlite.go | 5 ++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/graph/db/sql_store.go b/graph/db/sql_store.go index fa7a49206..48a6509f9 100644 --- a/graph/db/sql_store.go +++ b/graph/db/sql_store.go @@ -1,6 +1,8 @@ package graphdb import ( + "fmt" + "github.com/lightningnetwork/lnd/sqldb" ) @@ -37,9 +39,21 @@ var _ V1Store = (*SQLStore)(nil) // NewSQLStore creates a new SQLStore instance given an open BatchedSQLQueries // storage backend. -func NewSQLStore(db BatchedSQLQueries, kvStore *KVStore) *SQLStore { +func NewSQLStore(db BatchedSQLQueries, kvStore *KVStore, + options ...StoreOptionModifier) (*SQLStore, error) { + + opts := DefaultOptions() + for _, o := range options { + o(opts) + } + + if opts.NoMigration { + return nil, fmt.Errorf("the NoMigration option is not yet " + + "supported for SQL stores") + } + return &SQLStore{ db: db, KVStore: kvStore, - } + }, nil } diff --git a/graph/db/test_postgres.go b/graph/db/test_postgres.go index 7509a5907..2e38505f3 100644 --- a/graph/db/test_postgres.go +++ b/graph/db/test_postgres.go @@ -38,5 +38,8 @@ func NewTestDB(t testing.TB) V1Store { }, ) - return NewSQLStore(executor, graphStore) + store, err := NewSQLStore(executor, graphStore) + require.NoError(t, err) + + return store } diff --git a/graph/db/test_sqlite.go b/graph/db/test_sqlite.go index 601bba6fb..61373bfdd 100644 --- a/graph/db/test_sqlite.go +++ b/graph/db/test_sqlite.go @@ -31,5 +31,8 @@ func NewTestDB(t testing.TB) V1Store { }, ) - return NewSQLStore(executor, graphStore) + store, err := NewSQLStore(executor, graphStore) + require.NoError(t, err) + + return store }