db

package
v0.0.0-...-4d495be Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 22, 2022 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OrderAsc  = "asc"
	OrderDesc = "desc"
)

Variables

View Source
var ErrNotFound = errors.New("object not found")

ErrNotFound represents a not found error

View Source
var NewAnalyzerDAO = func(config *shared.AppConfig) (AnalyzerDAO, error) {
	client, err := NewDBClient(config)
	if err != nil {
		return nil, err
	}
	err = client.AutoMigrate(analyzer.Analyzer{})
	if err != nil {
		return nil, err
	}

	dao := &blobAnalyzerDAO{client: client, config: config}

	dao.preloadDefaultAnalyzersSilently(context.Background(), analyzersDataFile)

	return dao, nil
}

NewAnalyzerDAO create AnalyzerDAO

View Source
var NewAnalyzerRuleDAO = func(config *shared.AppConfig) (AnalyzerRuleDAO, error) {
	shared.LogInfof("init NewAnalyzerRuleDAO")
	client, err := NewDBClient(config)
	if err != nil {
		return nil, err
	}
	err = client.AutoMigrate(analyzer.Rule{})
	if err != nil {
		return nil, err
	}

	dao := &blobAnalyzerRuleDAO{client: client, config: config}

	err = dao.preloadDefaultAnalyzerRulesSilently(context.Background(), "internal/data", "rules")
	shared.LogInfof("preloading rules")
	if err != nil {
		shared.LogWarnf("failed to preload rules: %s", err.Error())
	} else {
		shared.LogInfof("preloaded rules")
	}

	return dao, nil
}

NewAnalyzerRuleDAO create AnalyzerRuleDAO

View Source
var NewOrganizationDAO = func(config *shared.AppConfig) (OrganizationDAO, error) {
	client, err := NewDBClient(config)
	if err != nil {
		return nil, err
	}
	err = client.AutoMigrate(models.Organization{})
	if err != nil {
		return nil, err
	}

	dao := &blobOrganizationDAO{client: client, config: config}
	return dao, nil
}

NewOrganizationDAO create OrganizationDAO

View Source
var NewServiceDAO = func(config *shared.AppConfig) (ServiceDAO, error) {
	client, err := NewDBClient(config)
	if err != nil {
		return nil, err
	}
	err = client.AutoMigrate(models.Service{})
	if err != nil {
		return nil, err
	}

	dao := &blobServiceDAO{client: client, config: config}
	return dao, nil
}

NewServiceDAO create ServiceDAO

View Source
var NewSpecAnalysisDAO = func(config *shared.AppConfig) (SpecAnalysisDAO, error) {
	client, err := NewDBClient(config)
	if err != nil {
		return nil, err
	}
	err = client.AutoMigrate(models.SpecAnalysis{})
	if err != nil {
		return nil, err
	}

	dao := &blobSpecAnalysisDAO{client: client, config: config}
	return dao, nil
}

NewSpecAnalysisDAO create SpecAnalysisDAO

View Source
var NewSpecDAO = func(config *shared.AppConfig) (SpecDAO, error) {
	client, err := NewDBClient(config)
	if err != nil {
		return nil, err
	}
	err = client.AutoMigrate(models.Spec{})
	if err != nil {
		return nil, err
	}

	dao := &blobSpecDAO{client: client, config: config}
	return dao, nil
}

NewSpecDAO create SpecDAO

View Source
var NewSpecDiffDAO = func(config *shared.AppConfig) (SpecDiffDAO, error) {
	client, err := NewDBClient(config)
	if err != nil {
		return nil, err
	}
	err = client.AutoMigrate(models.SpecDiff{})
	if err != nil {
		return nil, err
	}

	dao := &blobSpecDiffDAO{client: client, config: config}
	return dao, nil
}

NewSpecDiffDAO create SpecDiffDAO

Functions

func ClientFlags

func ClientFlags() []cli.Flag

ClientFlags returns cli flags for creating new db client

func Init

func Init(cfg *shared.AppConfig)

Init initializes service clients

Types

type AnalyzerDAO

type AnalyzerDAO interface {
	List(context context.Context, filter *ListFilter, withRules bool) ([]*analyzer.Analyzer, error)
	Save(context context.Context, analyzer *analyzer.Analyzer) error
	Get(context context.Context, id string) (*analyzer.Analyzer, error)
	Delete(context context.Context, id string) error
}

AnalyzerDAO is the interface to access database

type AnalyzerRuleDAO

type AnalyzerRuleDAO interface {
	List(ctx context.Context, filter *ListFilter) ([]*analyzer.Rule, error)
	Save(ctx context.Context, ar *analyzer.Rule) error
	Get(ctx context.Context, id string) (*analyzer.Rule, error)
	Delete(ctx context.Context, id string) error
	Import(ctx context.Context, ars []*analyzer.Rule) error
}

AnalyzerRuleDAO is the interface to access database

type Client

type Client struct {
	*gorm.DB
}

Client is a client for db service

func NewDBClient

func NewDBClient(cfg *shared.AppConfig) (*Client, error)

NewDBClient create a new Client

type ListFilter

type ListFilter struct {
	Model   models.ModelObject
	Indexes map[string]string
	Tags    []string
	Query   string
	Offset  int
	Limit   int

	Sorters []*Sorter
}

ListFilter represents request for List operation

func (*ListFilter) AddIndex

func (l *ListFilter) AddIndex(name, value string) *ListFilter

AddIndex adds new filter index

func (*ListFilter) From

func (l *ListFilter) From(req *restful.Request) error

From collects info from http request

func (*ListFilter) Pagination

func (l *ListFilter) Pagination(total int) models.Pagination

Pagination calculates pagination by offset, limit and total

type OrganizationDAO

type OrganizationDAO interface {
	List(context context.Context, filter *ListFilter, accessFilter *models.OrgServiceAccessDataFilter) ([]*models.Organization, error)
	Save(context context.Context, organization *models.Organization, accessFilter *models.OrgServiceAccessDataFilter) error
	Get(context context.Context, id string) (*models.Organization, error)
	Delete(context context.Context, id string) error
}

OrganizationDAO is the interface to access database

type ServiceDAO

type ServiceDAO interface {
	List(context context.Context, filter *ListFilter, accessFilter *models.OrgServiceAccessDataFilter) ([]*models.Service, error)
	Save(context context.Context, service *models.Service, accessFilter *models.OrgServiceAccessDataFilter) error
	Get(context context.Context, id string) (*models.Service, error)
	Delete(context context.Context, id string) error
}

ServiceDAO is the interface to access database

type Sorter

type Sorter struct {
	Order string
	Field string
}

func (*Sorter) OrderBy

func (m *Sorter) OrderBy() string

OrderBy returns MySQL order by value.

type SpecAnalysisDAO

type SpecAnalysisDAO interface {
	List(context context.Context, filter *ListFilter) ([]*models.SpecAnalysis, error)
	Save(context context.Context, specAnalysis *models.SpecAnalysis) error
	Get(context context.Context, id string) (*models.SpecAnalysis, error)
	Delete(context context.Context, id string) error
	BatchDeleteBySpecID(context context.Context, specID string) error
}

SpecAnalysisDAO is the interface to access database

type SpecDAO

type SpecDAO interface {
	List(context context.Context, filter *ListFilter, withDoc bool) ([]*models.Spec, error)
	Save(context context.Context, spec *models.Spec) error
	Get(context context.Context, id string, withDoc bool) (*models.Spec, error)
	Delete(context context.Context, id string) error
}

SpecDAO is the interface to access database

type SpecDiffDAO

type SpecDiffDAO interface {
	List(context context.Context, filter *ListFilter) ([]*models.SpecDiff, error)
	Save(context context.Context, specDiff *models.SpecDiff) error
	Get(context context.Context, id string) (*models.SpecDiff, error)
	Delete(context context.Context, id string) error
	BatchDeleteBySpecID(context context.Context, specID string) error
}

SpecDiffDAO is the interface to access database

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL