Skip to content

Commit 088ef6f

Browse files
committed
feat(entities) Adds batch dependent store interface and mysql implementation
1 parent 38380e3 commit 088ef6f

5 files changed

Lines changed: 47 additions & 11 deletions

File tree

extension/storage/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ load("@rules_go//go:def.bzl", "go_library")
33
go_library(
44
name = "storage",
55
srcs = [
6+
"batch_dependent_store.go",
67
"batch_store.go",
78
"change_provider_store.go",
89
"request_store.go",

extension/storage/mysql/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ load("@rules_go//go:def.bzl", "go_library")
33
go_library(
44
name = "mysql",
55
srcs = [
6+
"batch_dependent_store.go",
67
"batch_store.go",
78
"change_provider_store.go",
89
"request_store.go",

extension/storage/mysql/storage.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ type MySQLParameters struct {
2828
}
2929

3030
type mysqlStorage struct {
31-
db *sql.DB
32-
requestStore storage.RequestStore
33-
changeProviderStore storage.ChangeProviderStore
34-
batchStore storage.BatchStore
31+
db *sql.DB
32+
requestStore storage.RequestStore
33+
changeProviderStore storage.ChangeProviderStore
34+
batchStore storage.BatchStore
35+
batchDependentStore storage.BatchDependentStore
3536
}
3637

3738
// NewStorage creates a new MySQL storage.
@@ -52,10 +53,11 @@ func NewStorage(p MySQLParameters) (storage.Storage, error) {
5253
}
5354

5455
return &mysqlStorage{
55-
db: db,
56-
requestStore: NewRequestStore(db),
57-
changeProviderStore: NewChangeProviderStore(db),
58-
batchStore: NewBatchStore(db),
56+
db: db,
57+
requestStore: NewRequestStore(db),
58+
changeProviderStore: NewChangeProviderStore(db),
59+
batchStore: NewBatchStore(db),
60+
batchDependentStore: NewBatchDependentStore(db),
5961
}, nil
6062
}
6163

@@ -74,6 +76,11 @@ func (f *mysqlStorage) GetBatchStore() storage.BatchStore {
7476
return f.batchStore
7577
}
7678

79+
// GetBatchDependentStore returns the MySQL-backed BatchDependentStore.
80+
func (f *mysqlStorage) GetBatchDependentStore() storage.BatchDependentStore {
81+
return f.batchDependentStore
82+
}
83+
7784
// Close closes the underlying database connection.
7885
func (f *mysqlStorage) Close() error {
7986
return f.db.Close()

extension/storage/storage.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ type Storage interface {
3535
// GetBatchStore returns the BatchStore instance.
3636
GetBatchStore() BatchStore
3737

38+
// GetBatchDependentStore returns the BatchDependentStore instance.
39+
GetBatchDependentStore() BatchDependentStore
40+
3841
// Close closes the storage and all underlying connections. Should only be called once at the end of the program.
3942
Close() error
4043
}

gateway/controller/land_test.go

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,30 @@ func (m *mockBatchStore) UpdateState(ctx context.Context, id string, version int
7878
return nil
7979
}
8080

81+
type mockBatchDependentStore struct {
82+
createFunc func(ctx context.Context, batchDependent entity.BatchDependent) error
83+
getFunc func(ctx context.Context, batchID string) (entity.BatchDependent, error)
84+
}
85+
86+
func (m *mockBatchDependentStore) Get(ctx context.Context, batchID string) (entity.BatchDependent, error) {
87+
if m.getFunc != nil {
88+
return m.getFunc(ctx, batchID)
89+
}
90+
return entity.BatchDependent{}, nil
91+
}
92+
93+
func (m *mockBatchDependentStore) Create(ctx context.Context, batchDependent entity.BatchDependent) error {
94+
if m.createFunc != nil {
95+
return m.createFunc(ctx, batchDependent)
96+
}
97+
return nil
98+
}
99+
81100
type mockStorage struct {
82-
requestStore storage.RequestStore
83-
changeProviderStore storage.ChangeProviderStore
84-
batchStore storage.BatchStore
101+
requestStore storage.RequestStore
102+
changeProviderStore storage.ChangeProviderStore
103+
batchStore storage.BatchStore
104+
batchDependentStore storage.BatchDependentStore
85105
}
86106

87107
func (m *mockStorage) GetRequestStore() storage.RequestStore {
@@ -96,6 +116,10 @@ func (m *mockStorage) GetBatchStore() storage.BatchStore {
96116
return m.batchStore
97117
}
98118

119+
func (m *mockStorage) GetBatchDependentStore() storage.BatchDependentStore {
120+
return m.batchDependentStore
121+
}
122+
99123
func (m *mockStorage) Close() error {
100124
return nil
101125
}

0 commit comments

Comments
 (0)