@@ -11,16 +11,16 @@ import (
1111
1212 "github.com/SigNoz/signoz/pkg/query-service/interfaces"
1313 "github.com/SigNoz/signoz/pkg/query-service/model"
14+ "github.com/SigNoz/signoz/pkg/sqlstore"
1415 "github.com/SigNoz/signoz/pkg/types"
1516 "github.com/google/uuid"
16- "github.com/uptrace/bun"
1717
1818 "github.com/SigNoz/signoz/pkg/query-service/telemetry"
1919 "go.uber.org/zap"
2020)
2121
2222// This time the global variable is unexported.
23- var db * bun. DB
23+ var store sqlstore. SQLStore
2424
2525// User for mapping job,instance from grafana
2626var (
3333)
3434
3535// InitDB sets up setting up the connection pool global variable.
36- func InitDB (inputDB * bun. DB ) error {
37- db = inputDB
36+ func InitDB (sqlStore sqlstore. SQLStore ) error {
37+ store = sqlStore
3838 telemetry .GetInstance ().SetDashboardsInfoCallback (GetDashboardsInfo )
3939
4040 return nil
@@ -57,7 +57,7 @@ func CreateDashboard(ctx context.Context, orgID string, email string, data map[s
5757 dash .UUID = data ["uuid" ].(string )
5858 }
5959
60- err := db .NewInsert ().Model (dash ).Returning ("id" ).Scan (ctx , & dash .ID )
60+ err := store . BunDB () .NewInsert ().Model (dash ).Returning ("id" ).Scan (ctx , & dash .ID )
6161 if err != nil {
6262 zap .L ().Error ("Error in inserting dashboard data: " , zap .Any ("dashboard" , dash ), zap .Error (err ))
6363 return nil , & model.ApiError {Typ : model .ErrorExec , Err : err }
@@ -69,7 +69,7 @@ func CreateDashboard(ctx context.Context, orgID string, email string, data map[s
6969func GetDashboards (ctx context.Context , orgID string ) ([]types.Dashboard , * model.ApiError ) {
7070 dashboards := []types.Dashboard {}
7171
72- err := db .NewSelect ().Model (& dashboards ).Where ("org_id = ?" , orgID ).Scan (ctx )
72+ err := store . BunDB () .NewSelect ().Model (& dashboards ).Where ("org_id = ?" , orgID ).Scan (ctx )
7373 if err != nil {
7474 return nil , & model.ApiError {Typ : model .ErrorExec , Err : err }
7575 }
@@ -89,7 +89,7 @@ func DeleteDashboard(ctx context.Context, orgID, uuid string, fm interfaces.Feat
8989 return model .BadRequest (fmt .Errorf ("dashboard is locked, please unlock the dashboard to be able to delete it" ))
9090 }
9191
92- result , err := db .NewDelete ().Model (& types.Dashboard {}).Where ("org_id = ?" , orgID ).Where ("uuid = ?" , uuid ).Exec (ctx )
92+ result , err := store . BunDB () .NewDelete ().Model (& types.Dashboard {}).Where ("org_id = ?" , orgID ).Where ("uuid = ?" , uuid ).Exec (ctx )
9393 if err != nil {
9494 return & model.ApiError {Typ : model .ErrorExec , Err : err }
9595 }
@@ -108,7 +108,7 @@ func DeleteDashboard(ctx context.Context, orgID, uuid string, fm interfaces.Feat
108108func GetDashboard (ctx context.Context , orgID , uuid string ) (* types.Dashboard , * model.ApiError ) {
109109
110110 dashboard := types.Dashboard {}
111- err := db .NewSelect ().Model (& dashboard ).Where ("org_id = ?" , orgID ).Where ("uuid = ?" , uuid ).Scan (ctx )
111+ err := store . BunDB () .NewSelect ().Model (& dashboard ).Where ("org_id = ?" , orgID ).Where ("uuid = ?" , uuid ).Scan (ctx )
112112 if err != nil {
113113 return nil , & model.ApiError {Typ : model .ErrorNotFound , Err : fmt .Errorf ("no dashboard found with uuid: %s" , uuid )}
114114 }
@@ -148,7 +148,7 @@ func UpdateDashboard(ctx context.Context, orgID, userEmail, uuid string, data ma
148148 dashboard .UpdatedBy = userEmail
149149 dashboard .Data = data
150150
151- _ , err = db .NewUpdate ().Model (dashboard ).Set ("updated_at = ?" , dashboard .UpdatedAt ).Set ("updated_by = ?" , userEmail ).Set ("data = ?" , mapData ).Where ("uuid = ?" , dashboard .UUID ).Exec (ctx )
151+ _ , err = store . BunDB () .NewUpdate ().Model (dashboard ).Set ("updated_at = ?" , dashboard .UpdatedAt ).Set ("updated_by = ?" , userEmail ).Set ("data = ?" , mapData ).Where ("uuid = ?" , dashboard .UUID ).Exec (ctx )
152152
153153 if err != nil {
154154 zap .L ().Error ("Error in inserting dashboard data" , zap .Any ("data" , data ), zap .Error (err ))
@@ -170,7 +170,7 @@ func LockUnlockDashboard(ctx context.Context, orgID, uuid string, lock bool) *mo
170170 lockValue = 0
171171 }
172172
173- _ , err := db .NewUpdate ().Model (dashboard ).Set ("locked = ?" , lockValue ).Where ("org_id = ?" , orgID ).Where ("uuid = ?" , uuid ).Exec (ctx )
173+ _ , err := store . BunDB () .NewUpdate ().Model (dashboard ).Set ("locked = ?" , lockValue ).Where ("org_id = ?" , orgID ).Where ("uuid = ?" , uuid ).Exec (ctx )
174174 if err != nil {
175175 zap .L ().Error ("Error in updating dashboard" , zap .String ("uuid" , uuid ), zap .Error (err ))
176176 return & model.ApiError {Typ : model .ErrorExec , Err : err }
@@ -242,7 +242,7 @@ func GetDashboardsInfo(ctx context.Context) (*model.DashboardsInfo, error) {
242242 dashboardsInfo := model.DashboardsInfo {}
243243 // fetch dashboards from dashboard db
244244 dashboards := []types.Dashboard {}
245- err := db .NewSelect ().Model (& dashboards ).Scan (ctx )
245+ err := store . BunDB () .NewSelect ().Model (& dashboards ).Scan (ctx )
246246 if err != nil {
247247 zap .L ().Error ("Error in processing sql query" , zap .Error (err ))
248248 return & dashboardsInfo , err
@@ -451,7 +451,7 @@ func countPanelsInDashboard(inputData map[string]interface{}) model.DashboardsIn
451451
452452func GetDashboardsWithMetricNames (ctx context.Context , orgID string , metricNames []string ) (map [string ][]map [string ]string , * model.ApiError ) {
453453 dashboards := []types.Dashboard {}
454- err := db .NewSelect ().Model (& dashboards ).Where ("org_id = ?" , orgID ).Scan (ctx )
454+ err := store . BunDB () .NewSelect ().Model (& dashboards ).Where ("org_id = ?" , orgID ).Scan (ctx )
455455 if err != nil {
456456 zap .L ().Error ("Error in getting dashboards" , zap .Error (err ))
457457 return nil , & model.ApiError {Typ : model .ErrorExec , Err : err }
0 commit comments