2022-10-06 20:13:30 +05:30
|
|
|
package sqlite
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
|
2025-03-20 21:01:41 +05:30
|
|
|
basedao "github.com/SigNoz/signoz/pkg/query-service/dao"
|
|
|
|
|
basedsql "github.com/SigNoz/signoz/pkg/query-service/dao/sqlite"
|
|
|
|
|
baseint "github.com/SigNoz/signoz/pkg/query-service/interfaces"
|
|
|
|
|
"github.com/SigNoz/signoz/pkg/sqlstore"
|
2025-03-20 13:59:52 +05:30
|
|
|
"github.com/uptrace/bun"
|
2022-10-06 20:13:30 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type modelDao struct {
|
|
|
|
|
*basedsql.ModelDaoSqlite
|
|
|
|
|
flags baseint.FeatureLookup
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetFlagProvider sets the feature lookup provider
|
|
|
|
|
func (m *modelDao) SetFlagProvider(flags baseint.FeatureLookup) {
|
|
|
|
|
m.flags = flags
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CheckFeature confirms if a feature is available
|
|
|
|
|
func (m *modelDao) checkFeature(key string) error {
|
|
|
|
|
if m.flags == nil {
|
|
|
|
|
return fmt.Errorf("flag provider not set")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return m.flags.CheckFeature(key)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// InitDB creates and extends base model DB repository
|
2025-02-18 11:08:09 +05:30
|
|
|
func InitDB(sqlStore sqlstore.SQLStore) (*modelDao, error) {
|
|
|
|
|
dao, err := basedsql.InitDB(sqlStore)
|
2022-10-06 20:13:30 +05:30
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
// set package variable so dependent base methods (e.g. AuthCache) will work
|
|
|
|
|
basedao.SetDB(dao)
|
|
|
|
|
m := &modelDao{ModelDaoSqlite: dao}
|
|
|
|
|
return m, nil
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-20 13:59:52 +05:30
|
|
|
func (m *modelDao) DB() *bun.DB {
|
2022-10-06 20:13:30 +05:30
|
|
|
return m.ModelDaoSqlite.DB()
|
|
|
|
|
}
|