From 91877c30165cd90e5e9053ccf604c06ca0796950 Mon Sep 17 00:00:00 2001 From: Doug Lauder Date: Thu, 30 Jun 2022 08:28:37 -0400 Subject: [PATCH] Add Store service for Focalboard multi-product architecture (#20568) * add Store service --- app/server.go | 2 ++ product/api.go | 8 ++++++++ store/store.go | 15 +++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/app/server.go b/app/server.go index 39e490a209..c148a9a2b5 100644 --- a/app/server.go +++ b/app/server.go @@ -102,6 +102,7 @@ const ( LogKey ServiceKey = "log" HooksKey ServiceKey = "hooks" KVStoreKey ServiceKey = "kvstore" + StoreKey ServiceKey = "storekey" ) type Server struct { @@ -402,6 +403,7 @@ func NewServer(options ...Option) (*Server, error) { LogKey: s.GetLogger(), CloudKey: &cloudWrapper{cloud: s.Cloud}, KVStoreKey: &kvStoreWrapper{srv: s}, + StoreKey: store.NewStoreServiceAdapter(s.Store), } // Step 8: Initialize products. diff --git a/product/api.go b/product/api.go index c9ae90db34..a81f41412a 100644 --- a/product/api.go +++ b/product/api.go @@ -4,6 +4,7 @@ package product import ( + "database/sql" "io" "github.com/gorilla/mux" @@ -167,3 +168,10 @@ type KVStoreService interface { type LogService interface { mlog.LoggerIFace } + +// StoreService is the API for accessing the Store service APIs. +// +// The service shall be registered via app.StoreKey service key. +type StoreService interface { + GetMasterDB() *sql.DB +} diff --git a/store/store.go b/store/store.go index 64198e7635..9d535e0449 100644 --- a/store/store.go +++ b/store/store.go @@ -1021,3 +1021,18 @@ type SidebarCategorySearchOpts struct { TeamID string ExcludeTeam bool } + +// StoreServiceAdapter provides a simple Store wrapper for use with products. +type StoreServiceAdapter struct { + store Store +} + +func NewStoreServiceAdapter(store Store) *StoreServiceAdapter { + return &StoreServiceAdapter{ + store: store, + } +} + +func (a *StoreServiceAdapter) GetMasterDB() *sql.DB { + return a.store.GetInternalMasterDB() +}