fix: use sqlStore instead of bun.db (#7416)

* fix: use sqlStore instead of bun.db

* fix: get it to running state

* fix: name changes
This commit is contained in:
Nityananda Gohain 2025-03-24 14:54:20 +05:30 committed by GitHub
parent 9bdf194d70
commit 4842e3b912
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 51 additions and 51 deletions

View File

@ -4,20 +4,20 @@ import (
"net/http" "net/http"
"time" "time"
"github.com/SigNoz/signoz/pkg/sqlstore"
"github.com/SigNoz/signoz/pkg/types" "github.com/SigNoz/signoz/pkg/types"
"github.com/SigNoz/signoz/pkg/types/authtypes" "github.com/SigNoz/signoz/pkg/types/authtypes"
"github.com/uptrace/bun"
"go.uber.org/zap" "go.uber.org/zap"
) )
type Pat struct { type Pat struct {
db *bun.DB store sqlstore.SQLStore
uuid *authtypes.UUID uuid *authtypes.UUID
headers []string headers []string
} }
func NewPat(db *bun.DB, headers []string) *Pat { func NewPat(store sqlstore.SQLStore, headers []string) *Pat {
return &Pat{db: db, uuid: authtypes.NewUUID(), headers: headers} return &Pat{store: store, uuid: authtypes.NewUUID(), headers: headers}
} }
func (p *Pat) Wrap(next http.Handler) http.Handler { func (p *Pat) Wrap(next http.Handler) http.Handler {
@ -41,7 +41,7 @@ func (p *Pat) Wrap(next http.Handler) http.Handler {
return return
} }
err = p.db.NewSelect().Model(&pat).Where("token = ?", patToken).Scan(r.Context()) err = p.store.BunDB().NewSelect().Model(&pat).Where("token = ?", patToken).Scan(r.Context())
if err != nil { if err != nil {
next.ServeHTTP(w, r) next.ServeHTTP(w, r)
return return
@ -54,7 +54,7 @@ func (p *Pat) Wrap(next http.Handler) http.Handler {
// get user from db // get user from db
user := types.User{} user := types.User{}
err = p.db.NewSelect().Model(&user).Where("id = ?", pat.UserID).Scan(r.Context()) err = p.store.BunDB().NewSelect().Model(&user).Where("id = ?", pat.UserID).Scan(r.Context())
if err != nil { if err != nil {
next.ServeHTTP(w, r) next.ServeHTTP(w, r)
return return
@ -74,7 +74,7 @@ func (p *Pat) Wrap(next http.Handler) http.Handler {
next.ServeHTTP(w, r) next.ServeHTTP(w, r)
pat.LastUsed = time.Now().Unix() pat.LastUsed = time.Now().Unix()
_, err = p.db.NewUpdate().Model(&pat).Column("last_used").Where("token = ?", patToken).Where("revoked = false").Exec(r.Context()) _, err = p.store.BunDB().NewUpdate().Model(&pat).Column("last_used").Where("token = ?", patToken).Where("revoked = false").Exec(r.Context())
if err != nil { if err != nil {
zap.L().Error("Failed to update PAT last used in db, err: %v", zap.Error(err)) zap.L().Error("Failed to update PAT last used in db, err: %v", zap.Error(err))
} }

View File

@ -112,7 +112,7 @@ func NewServer(serverOptions *ServerOptions) (*Server, error) {
return nil, err return nil, err
} }
if err := baseexplorer.InitWithDSN(serverOptions.SigNoz.SQLStore.BunDB()); err != nil { if err := baseexplorer.InitWithDSN(serverOptions.SigNoz.SQLStore); err != nil {
return nil, err return nil, err
} }
@ -120,7 +120,7 @@ func NewServer(serverOptions *ServerOptions) (*Server, error) {
return nil, err return nil, err
} }
if err := dashboards.InitDB(serverOptions.SigNoz.SQLStore.BunDB()); err != nil { if err := dashboards.InitDB(serverOptions.SigNoz.SQLStore); err != nil {
return nil, err return nil, err
} }
@ -130,7 +130,7 @@ func NewServer(serverOptions *ServerOptions) (*Server, error) {
} }
// initiate license manager // initiate license manager
lm, err := licensepkg.StartManager(serverOptions.SigNoz.SQLStore.SQLxDB(), serverOptions.SigNoz.SQLStore.BunDB()) lm, err := licensepkg.StartManager(serverOptions.SigNoz.SQLStore.SQLxDB(), serverOptions.SigNoz.SQLStore)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -317,7 +317,7 @@ func (s *Server) createPrivateServer(apiHandler *api.APIHandler) (*http.Server,
r := baseapp.NewRouter() r := baseapp.NewRouter()
r.Use(middleware.NewAuth(zap.L(), s.serverOptions.Jwt, []string{"Authorization", "Sec-WebSocket-Protocol"}).Wrap) r.Use(middleware.NewAuth(zap.L(), s.serverOptions.Jwt, []string{"Authorization", "Sec-WebSocket-Protocol"}).Wrap)
r.Use(eemiddleware.NewPat(s.serverOptions.SigNoz.SQLStore.BunDB(), []string{"SIGNOZ-API-KEY"}).Wrap) r.Use(eemiddleware.NewPat(s.serverOptions.SigNoz.SQLStore, []string{"SIGNOZ-API-KEY"}).Wrap)
r.Use(middleware.NewTimeout(zap.L(), r.Use(middleware.NewTimeout(zap.L(),
s.serverOptions.Config.APIServer.Timeout.ExcludedRoutes, s.serverOptions.Config.APIServer.Timeout.ExcludedRoutes,
s.serverOptions.Config.APIServer.Timeout.Default, s.serverOptions.Config.APIServer.Timeout.Default,
@ -365,7 +365,7 @@ func (s *Server) createPublicServer(apiHandler *api.APIHandler, web web.Web) (*h
am := baseapp.NewAuthMiddleware(getUserFromRequest) am := baseapp.NewAuthMiddleware(getUserFromRequest)
r.Use(middleware.NewAuth(zap.L(), s.serverOptions.Jwt, []string{"Authorization", "Sec-WebSocket-Protocol"}).Wrap) r.Use(middleware.NewAuth(zap.L(), s.serverOptions.Jwt, []string{"Authorization", "Sec-WebSocket-Protocol"}).Wrap)
r.Use(eemiddleware.NewPat(s.serverOptions.SigNoz.SQLStore.BunDB(), []string{"SIGNOZ-API-KEY"}).Wrap) r.Use(eemiddleware.NewPat(s.serverOptions.SigNoz.SQLStore, []string{"SIGNOZ-API-KEY"}).Wrap)
r.Use(middleware.NewTimeout(zap.L(), r.Use(middleware.NewTimeout(zap.L(),
s.serverOptions.Config.APIServer.Timeout.ExcludedRoutes, s.serverOptions.Config.APIServer.Timeout.ExcludedRoutes,
s.serverOptions.Config.APIServer.Timeout.Default, s.serverOptions.Config.APIServer.Timeout.Default,

View File

@ -9,10 +9,10 @@ import (
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"github.com/mattn/go-sqlite3" "github.com/mattn/go-sqlite3"
"github.com/uptrace/bun"
"github.com/SigNoz/signoz/ee/query-service/model" "github.com/SigNoz/signoz/ee/query-service/model"
basemodel "github.com/SigNoz/signoz/pkg/query-service/model" basemodel "github.com/SigNoz/signoz/pkg/query-service/model"
"github.com/SigNoz/signoz/pkg/sqlstore"
"github.com/SigNoz/signoz/pkg/types" "github.com/SigNoz/signoz/pkg/types"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -20,14 +20,14 @@ import (
// Repo is license repo. stores license keys in a secured DB // Repo is license repo. stores license keys in a secured DB
type Repo struct { type Repo struct {
db *sqlx.DB db *sqlx.DB
bundb *bun.DB store sqlstore.SQLStore
} }
// NewLicenseRepo initiates a new license repo // NewLicenseRepo initiates a new license repo
func NewLicenseRepo(db *sqlx.DB, bundb *bun.DB) Repo { func NewLicenseRepo(db *sqlx.DB, store sqlstore.SQLStore) Repo {
return Repo{ return Repo{
db: db, db: db,
bundb: bundb, store: store,
} }
} }
@ -171,7 +171,7 @@ func (r *Repo) UpdateLicenseV3(ctx context.Context, l *model.LicenseV3) error {
func (r *Repo) CreateFeature(req *types.FeatureStatus) *basemodel.ApiError { func (r *Repo) CreateFeature(req *types.FeatureStatus) *basemodel.ApiError {
_, err := r.bundb.NewInsert(). _, err := r.store.BunDB().NewInsert().
Model(req). Model(req).
Exec(context.Background()) Exec(context.Background())
if err != nil { if err != nil {
@ -183,7 +183,7 @@ func (r *Repo) CreateFeature(req *types.FeatureStatus) *basemodel.ApiError {
func (r *Repo) GetFeature(featureName string) (types.FeatureStatus, error) { func (r *Repo) GetFeature(featureName string) (types.FeatureStatus, error) {
var feature types.FeatureStatus var feature types.FeatureStatus
err := r.bundb.NewSelect(). err := r.store.BunDB().NewSelect().
Model(&feature). Model(&feature).
Where("name = ?", featureName). Where("name = ?", featureName).
Scan(context.Background()) Scan(context.Background())
@ -212,7 +212,7 @@ func (r *Repo) GetAllFeatures() ([]basemodel.Feature, error) {
func (r *Repo) UpdateFeature(req types.FeatureStatus) error { func (r *Repo) UpdateFeature(req types.FeatureStatus) error {
_, err := r.bundb.NewUpdate(). _, err := r.store.BunDB().NewUpdate().
Model(&req). Model(&req).
Where("name = ?", req.Name). Where("name = ?", req.Name).
Exec(context.Background()) Exec(context.Background())

View File

@ -7,11 +7,11 @@ import (
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/uptrace/bun"
"sync" "sync"
baseconstants "github.com/SigNoz/signoz/pkg/query-service/constants" baseconstants "github.com/SigNoz/signoz/pkg/query-service/constants"
"github.com/SigNoz/signoz/pkg/sqlstore"
"github.com/SigNoz/signoz/pkg/types" "github.com/SigNoz/signoz/pkg/types"
"github.com/SigNoz/signoz/pkg/types/authtypes" "github.com/SigNoz/signoz/pkg/types/authtypes"
@ -45,12 +45,12 @@ type Manager struct {
activeFeatures basemodel.FeatureSet activeFeatures basemodel.FeatureSet
} }
func StartManager(db *sqlx.DB, bundb *bun.DB, features ...basemodel.Feature) (*Manager, error) { func StartManager(db *sqlx.DB, store sqlstore.SQLStore, features ...basemodel.Feature) (*Manager, error) {
if LM != nil { if LM != nil {
return LM, nil return LM, nil
} }
repo := NewLicenseRepo(db, bundb) repo := NewLicenseRepo(db, store)
m := &Manager{ m := &Manager{
repo: &repo, repo: &repo,
} }

View File

@ -11,16 +11,16 @@ import (
"github.com/SigNoz/signoz/pkg/query-service/interfaces" "github.com/SigNoz/signoz/pkg/query-service/interfaces"
"github.com/SigNoz/signoz/pkg/query-service/model" "github.com/SigNoz/signoz/pkg/query-service/model"
"github.com/SigNoz/signoz/pkg/sqlstore"
"github.com/SigNoz/signoz/pkg/types" "github.com/SigNoz/signoz/pkg/types"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/uptrace/bun"
"github.com/SigNoz/signoz/pkg/query-service/telemetry" "github.com/SigNoz/signoz/pkg/query-service/telemetry"
"go.uber.org/zap" "go.uber.org/zap"
) )
// This time the global variable is unexported. // This time the global variable is unexported.
var db *bun.DB var store sqlstore.SQLStore
// User for mapping job,instance from grafana // User for mapping job,instance from grafana
var ( var (
@ -33,8 +33,8 @@ var (
) )
// InitDB sets up setting up the connection pool global variable. // InitDB sets up setting up the connection pool global variable.
func InitDB(inputDB *bun.DB) error { func InitDB(sqlStore sqlstore.SQLStore) error {
db = inputDB store = sqlStore
telemetry.GetInstance().SetDashboardsInfoCallback(GetDashboardsInfo) telemetry.GetInstance().SetDashboardsInfoCallback(GetDashboardsInfo)
return nil return nil
@ -57,7 +57,7 @@ func CreateDashboard(ctx context.Context, orgID string, email string, data map[s
dash.UUID = data["uuid"].(string) dash.UUID = data["uuid"].(string)
} }
err := db.NewInsert().Model(dash).Returning("id").Scan(ctx, &dash.ID) err := store.BunDB().NewInsert().Model(dash).Returning("id").Scan(ctx, &dash.ID)
if err != nil { if err != nil {
zap.L().Error("Error in inserting dashboard data: ", zap.Any("dashboard", dash), zap.Error(err)) zap.L().Error("Error in inserting dashboard data: ", zap.Any("dashboard", dash), zap.Error(err))
return nil, &model.ApiError{Typ: model.ErrorExec, Err: err} 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
func GetDashboards(ctx context.Context, orgID string) ([]types.Dashboard, *model.ApiError) { func GetDashboards(ctx context.Context, orgID string) ([]types.Dashboard, *model.ApiError) {
dashboards := []types.Dashboard{} dashboards := []types.Dashboard{}
err := db.NewSelect().Model(&dashboards).Where("org_id = ?", orgID).Scan(ctx) err := store.BunDB().NewSelect().Model(&dashboards).Where("org_id = ?", orgID).Scan(ctx)
if err != nil { if err != nil {
return nil, &model.ApiError{Typ: model.ErrorExec, Err: err} return nil, &model.ApiError{Typ: model.ErrorExec, Err: err}
} }
@ -89,7 +89,7 @@ func DeleteDashboard(ctx context.Context, orgID, uuid string, fm interfaces.Feat
return model.BadRequest(fmt.Errorf("dashboard is locked, please unlock the dashboard to be able to delete it")) return model.BadRequest(fmt.Errorf("dashboard is locked, please unlock the dashboard to be able to delete it"))
} }
result, err := db.NewDelete().Model(&types.Dashboard{}).Where("org_id = ?", orgID).Where("uuid = ?", uuid).Exec(ctx) result, err := store.BunDB().NewDelete().Model(&types.Dashboard{}).Where("org_id = ?", orgID).Where("uuid = ?", uuid).Exec(ctx)
if err != nil { if err != nil {
return &model.ApiError{Typ: model.ErrorExec, Err: err} return &model.ApiError{Typ: model.ErrorExec, Err: err}
} }
@ -108,7 +108,7 @@ func DeleteDashboard(ctx context.Context, orgID, uuid string, fm interfaces.Feat
func GetDashboard(ctx context.Context, orgID, uuid string) (*types.Dashboard, *model.ApiError) { func GetDashboard(ctx context.Context, orgID, uuid string) (*types.Dashboard, *model.ApiError) {
dashboard := types.Dashboard{} dashboard := types.Dashboard{}
err := db.NewSelect().Model(&dashboard).Where("org_id = ?", orgID).Where("uuid = ?", uuid).Scan(ctx) err := store.BunDB().NewSelect().Model(&dashboard).Where("org_id = ?", orgID).Where("uuid = ?", uuid).Scan(ctx)
if err != nil { if err != nil {
return nil, &model.ApiError{Typ: model.ErrorNotFound, Err: fmt.Errorf("no dashboard found with uuid: %s", uuid)} return nil, &model.ApiError{Typ: model.ErrorNotFound, Err: fmt.Errorf("no dashboard found with uuid: %s", uuid)}
} }
@ -148,7 +148,7 @@ func UpdateDashboard(ctx context.Context, orgID, userEmail, uuid string, data ma
dashboard.UpdatedBy = userEmail dashboard.UpdatedBy = userEmail
dashboard.Data = data dashboard.Data = data
_, err = db.NewUpdate().Model(dashboard).Set("updated_at = ?", dashboard.UpdatedAt).Set("updated_by = ?", userEmail).Set("data = ?", mapData).Where("uuid = ?", dashboard.UUID).Exec(ctx) _, err = store.BunDB().NewUpdate().Model(dashboard).Set("updated_at = ?", dashboard.UpdatedAt).Set("updated_by = ?", userEmail).Set("data = ?", mapData).Where("uuid = ?", dashboard.UUID).Exec(ctx)
if err != nil { if err != nil {
zap.L().Error("Error in inserting dashboard data", zap.Any("data", data), zap.Error(err)) 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
lockValue = 0 lockValue = 0
} }
_, err := db.NewUpdate().Model(dashboard).Set("locked = ?", lockValue).Where("org_id = ?", orgID).Where("uuid = ?", uuid).Exec(ctx) _, err := store.BunDB().NewUpdate().Model(dashboard).Set("locked = ?", lockValue).Where("org_id = ?", orgID).Where("uuid = ?", uuid).Exec(ctx)
if err != nil { if err != nil {
zap.L().Error("Error in updating dashboard", zap.String("uuid", uuid), zap.Error(err)) zap.L().Error("Error in updating dashboard", zap.String("uuid", uuid), zap.Error(err))
return &model.ApiError{Typ: model.ErrorExec, Err: err} return &model.ApiError{Typ: model.ErrorExec, Err: err}
@ -242,7 +242,7 @@ func GetDashboardsInfo(ctx context.Context) (*model.DashboardsInfo, error) {
dashboardsInfo := model.DashboardsInfo{} dashboardsInfo := model.DashboardsInfo{}
// fetch dashboards from dashboard db // fetch dashboards from dashboard db
dashboards := []types.Dashboard{} dashboards := []types.Dashboard{}
err := db.NewSelect().Model(&dashboards).Scan(ctx) err := store.BunDB().NewSelect().Model(&dashboards).Scan(ctx)
if err != nil { if err != nil {
zap.L().Error("Error in processing sql query", zap.Error(err)) zap.L().Error("Error in processing sql query", zap.Error(err))
return &dashboardsInfo, err return &dashboardsInfo, err
@ -451,7 +451,7 @@ func countPanelsInDashboard(inputData map[string]interface{}) model.DashboardsIn
func GetDashboardsWithMetricNames(ctx context.Context, orgID string, metricNames []string) (map[string][]map[string]string, *model.ApiError) { func GetDashboardsWithMetricNames(ctx context.Context, orgID string, metricNames []string) (map[string][]map[string]string, *model.ApiError) {
dashboards := []types.Dashboard{} dashboards := []types.Dashboard{}
err := db.NewSelect().Model(&dashboards).Where("org_id = ?", orgID).Scan(ctx) err := store.BunDB().NewSelect().Model(&dashboards).Where("org_id = ?", orgID).Scan(ctx)
if err != nil { if err != nil {
zap.L().Error("Error in getting dashboards", zap.Error(err)) zap.L().Error("Error in getting dashboards", zap.Error(err))
return nil, &model.ApiError{Typ: model.ErrorExec, Err: err} return nil, &model.ApiError{Typ: model.ErrorExec, Err: err}

View File

@ -11,30 +11,30 @@ import (
"github.com/SigNoz/signoz/pkg/query-service/model" "github.com/SigNoz/signoz/pkg/query-service/model"
v3 "github.com/SigNoz/signoz/pkg/query-service/model/v3" v3 "github.com/SigNoz/signoz/pkg/query-service/model/v3"
"github.com/SigNoz/signoz/pkg/query-service/telemetry" "github.com/SigNoz/signoz/pkg/query-service/telemetry"
"github.com/SigNoz/signoz/pkg/sqlstore"
"github.com/SigNoz/signoz/pkg/types" "github.com/SigNoz/signoz/pkg/types"
"github.com/SigNoz/signoz/pkg/types/authtypes" "github.com/SigNoz/signoz/pkg/types/authtypes"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/uptrace/bun"
"go.uber.org/zap" "go.uber.org/zap"
) )
var db *bun.DB var store sqlstore.SQLStore
// InitWithDSN sets up setting up the connection pool global variable. // InitWithDSN sets up setting up the connection pool global variable.
func InitWithDSN(inputDB *bun.DB) error { func InitWithDSN(sqlStore sqlstore.SQLStore) error {
db = inputDB store = sqlStore
telemetry.GetInstance().SetSavedViewsInfoCallback(GetSavedViewsInfo) telemetry.GetInstance().SetSavedViewsInfoCallback(GetSavedViewsInfo)
return nil return nil
} }
func InitWithDB(bunDB *bun.DB) { func InitWithDB(sqlStore sqlstore.SQLStore) {
db = bunDB store = sqlStore
} }
func GetViews(ctx context.Context, orgID string) ([]*v3.SavedView, error) { func GetViews(ctx context.Context, orgID string) ([]*v3.SavedView, error) {
var views []types.SavedView var views []types.SavedView
err := db.NewSelect().Model(&views).Where("org_id = ?", orgID).Scan(ctx) err := store.BunDB().NewSelect().Model(&views).Where("org_id = ?", orgID).Scan(ctx)
if err != nil { if err != nil {
return nil, fmt.Errorf("error in getting saved views: %s", err.Error()) return nil, fmt.Errorf("error in getting saved views: %s", err.Error())
} }
@ -67,9 +67,9 @@ func GetViewsForFilters(ctx context.Context, orgID string, sourcePage string, na
var views []types.SavedView var views []types.SavedView
var err error var err error
if len(category) == 0 { if len(category) == 0 {
err = db.NewSelect().Model(&views).Where("org_id = ? AND source_page = ? AND name LIKE ?", orgID, sourcePage, "%"+name+"%").Scan(ctx) err = store.BunDB().NewSelect().Model(&views).Where("org_id = ? AND source_page = ? AND name LIKE ?", orgID, sourcePage, "%"+name+"%").Scan(ctx)
} else { } else {
err = db.NewSelect().Model(&views).Where("org_id = ? AND source_page = ? AND category LIKE ? AND name LIKE ?", orgID, sourcePage, "%"+category+"%", "%"+name+"%").Scan(ctx) err = store.BunDB().NewSelect().Model(&views).Where("org_id = ? AND source_page = ? AND category LIKE ? AND name LIKE ?", orgID, sourcePage, "%"+category+"%", "%"+name+"%").Scan(ctx)
} }
if err != nil { if err != nil {
return nil, fmt.Errorf("error in getting saved views: %s", err.Error()) return nil, fmt.Errorf("error in getting saved views: %s", err.Error())
@ -139,7 +139,7 @@ func CreateView(ctx context.Context, orgID string, view v3.SavedView) (string, e
ExtraData: view.ExtraData, ExtraData: view.ExtraData,
} }
_, err = db.NewInsert().Model(&dbView).Exec(ctx) _, err = store.BunDB().NewInsert().Model(&dbView).Exec(ctx)
if err != nil { if err != nil {
return "", fmt.Errorf("error in creating saved view: %s", err.Error()) return "", fmt.Errorf("error in creating saved view: %s", err.Error())
} }
@ -148,7 +148,7 @@ func CreateView(ctx context.Context, orgID string, view v3.SavedView) (string, e
func GetView(ctx context.Context, orgID string, uuid_ string) (*v3.SavedView, error) { func GetView(ctx context.Context, orgID string, uuid_ string) (*v3.SavedView, error) {
var view types.SavedView var view types.SavedView
err := db.NewSelect().Model(&view).Where("org_id = ? AND uuid = ?", orgID, uuid_).Scan(ctx) err := store.BunDB().NewSelect().Model(&view).Where("org_id = ? AND uuid = ?", orgID, uuid_).Scan(ctx)
if err != nil { if err != nil {
return nil, fmt.Errorf("error in getting saved view: %s", err.Error()) return nil, fmt.Errorf("error in getting saved view: %s", err.Error())
} }
@ -187,7 +187,7 @@ func UpdateView(ctx context.Context, orgID string, uuid_ string, view v3.SavedVi
updatedAt := time.Now() updatedAt := time.Now()
updatedBy := claims.Email updatedBy := claims.Email
_, err = db.NewUpdate(). _, err = store.BunDB().NewUpdate().
Model(&types.SavedView{}). Model(&types.SavedView{}).
Set("updated_at = ?, updated_by = ?, name = ?, category = ?, source_page = ?, tags = ?, data = ?, extra_data = ?", Set("updated_at = ?, updated_by = ?, name = ?, category = ?, source_page = ?, tags = ?, data = ?, extra_data = ?",
updatedAt, updatedBy, view.Name, view.Category, view.SourcePage, strings.Join(view.Tags, ","), data, view.ExtraData). updatedAt, updatedBy, view.Name, view.Category, view.SourcePage, strings.Join(view.Tags, ","), data, view.ExtraData).
@ -201,7 +201,7 @@ func UpdateView(ctx context.Context, orgID string, uuid_ string, view v3.SavedVi
} }
func DeleteView(ctx context.Context, orgID string, uuid_ string) error { func DeleteView(ctx context.Context, orgID string, uuid_ string) error {
_, err := db.NewDelete(). _, err := store.BunDB().NewDelete().
Model(&types.SavedView{}). Model(&types.SavedView{}).
Where("uuid = ?", uuid_). Where("uuid = ?", uuid_).
Where("org_id = ?", orgID). Where("org_id = ?", orgID).
@ -216,7 +216,7 @@ func GetSavedViewsInfo(ctx context.Context) (*model.SavedViewsInfo, error) {
savedViewsInfo := model.SavedViewsInfo{} savedViewsInfo := model.SavedViewsInfo{}
// get single org ID from db // get single org ID from db
var orgIDs []string var orgIDs []string
err := db.NewSelect().Model((*types.Organization)(nil)).Column("id").Scan(ctx, &orgIDs) err := store.BunDB().NewSelect().Model((*types.Organization)(nil)).Column("id").Scan(ctx, &orgIDs)
if err != nil { if err != nil {
return nil, fmt.Errorf("error in getting org IDs: %s", err.Error()) return nil, fmt.Errorf("error in getting org IDs: %s", err.Error())
} }

View File

@ -101,11 +101,11 @@ func NewServer(serverOptions *ServerOptions) (*Server, error) {
return nil, err return nil, err
} }
if err := dashboards.InitDB(serverOptions.SigNoz.SQLStore.BunDB()); err != nil { if err := dashboards.InitDB(serverOptions.SigNoz.SQLStore); err != nil {
return nil, err return nil, err
} }
if err := explorer.InitWithDSN(serverOptions.SigNoz.SQLStore.BunDB()); err != nil { if err := explorer.InitWithDSN(serverOptions.SigNoz.SQLStore); err != nil {
return nil, err return nil, err
} }

View File

@ -72,7 +72,7 @@ func NewQueryServiceDBForTests(t *testing.T) sqlstore.SQLStore {
if err != nil { if err != nil {
t.Fatalf("could not initialize dao: %v", err) t.Fatalf("could not initialize dao: %v", err)
} }
_ = dashboards.InitDB(sqlStore.BunDB()) _ = dashboards.InitDB(sqlStore)
return sqlStore return sqlStore
} }