sqleng

package
v0.0.0-...-fb7f86c Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2023 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const MetaKeyExecutedQueryString = "executedQueryString"

MetaKeyExecutedQueryString is the key where the executed query should get stored

Variables

View Source
var ErrConnectionFailed = errutil.NewBase(errutil.StatusInternal, "sqleng.connectionError")
View Source
var Interpolate = func(query backend.DataQuery, timeRange backend.TimeRange, timeInterval string, sql string) (string, error) {
	minInterval, err := intervalv2.GetIntervalFrom(timeInterval, query.Interval.String(), query.Interval.Milliseconds(), time.Second*60)
	if err != nil {
		return "", err
	}
	interval := sqlIntervalCalculator.Calculate(timeRange, minInterval, query.MaxDataPoints)

	sql = strings.ReplaceAll(sql, "$__interval_ms", strconv.FormatInt(interval.Milliseconds(), 10))
	sql = strings.ReplaceAll(sql, "$__interval", interval.Text)
	sql = strings.ReplaceAll(sql, "$__unixEpochFrom()", fmt.Sprintf("%d", timeRange.From.UTC().Unix()))
	sql = strings.ReplaceAll(sql, "$__unixEpochTo()", fmt.Sprintf("%d", timeRange.To.UTC().Unix()))

	return sql, nil
}

Interpolate provides global macros/substitutions for all sql datasources.

View Source
var NewXormEngine = func(driverName string, connectionString string) (*xorm.Engine, error) {
	return xorm.NewEngine(driverName, connectionString)
}

NewXormEngine is an xorm.Engine factory, that can be stubbed by tests.

View Source
var XormDriverMu sync.RWMutex

XormDriverMu is used to allow safe concurrent registering and querying of drivers in xorm

Functions

func SetupFillmode

func SetupFillmode(query *backend.DataQuery, interval time.Duration, fillmode string) error

Types

type DBDataResponse

type DBDataResponse struct {
	// contains filtered or unexported fields
}

type DataPluginConfiguration

type DataPluginConfiguration struct {
	DriverName        string
	DSInfo            DataSourceInfo
	ConnectionString  string
	TimeColumnNames   []string
	MetricColumnTypes []string
	RowLimit          int64
}

type DataSourceHandler

type DataSourceHandler struct {
	// contains filtered or unexported fields
}

func NewQueryDataHandler

func NewQueryDataHandler(cfg *setting.Cfg, config DataPluginConfiguration, queryResultTransformer SqlQueryResultTransformer,
	macroEngine SQLMacroEngine, log log.Logger) (*DataSourceHandler, error)

func (*DataSourceHandler) Dispose

func (e *DataSourceHandler) Dispose()

func (*DataSourceHandler) Ping

func (e *DataSourceHandler) Ping() error

func (*DataSourceHandler) QueryData

func (*DataSourceHandler) TransformQueryError

func (e *DataSourceHandler) TransformQueryError(logger log.Logger, err error) error

type DataSourceInfo

type DataSourceInfo struct {
	JsonData                JsonData
	URL                     string
	User                    string
	Database                string
	ID                      int64
	Updated                 time.Time
	UID                     string
	DecryptedSecureJSONData map[string]string
}

type DefaultConnectionInfo

type DefaultConnectionInfo struct {
	MaxOpenConns    int
	MaxIdleConns    int
	ConnMaxLifetime int
}

Defaults for the xorm connection pool

type JsonData

type JsonData struct {
	MaxOpenConns            int    `json:"maxOpenConns"`
	MaxIdleConns            int    `json:"maxIdleConns"`
	ConnMaxLifetime         int    `json:"connMaxLifetime"`
	ConnectionTimeout       int    `json:"connectionTimeout"`
	Timescaledb             bool   `json:"timescaledb"`
	Mode                    string `json:"sslmode"`
	ConfigurationMethod     string `json:"tlsConfigurationMethod"`
	TlsSkipVerify           bool   `json:"tlsSkipVerify"`
	RootCertFile            string `json:"sslRootCertFile"`
	CertFile                string `json:"sslCertFile"`
	CertKeyFile             string `json:"sslKeyFile"`
	Timezone                string `json:"timezone"`
	Encrypt                 string `json:"encrypt"`
	Servername              string `json:"servername"`
	TimeInterval            string `json:"timeInterval"`
	Database                string `json:"database"`
	SecureDSProxy           bool   `json:"enableSecureSocksProxy"`
	AllowCleartextPasswords bool   `json:"allowCleartextPasswords"`
}

type QueryJson

type QueryJson struct {
	RawSql       string  `json:"rawSql"`
	Fill         bool    `json:"fill"`
	FillInterval float64 `json:"fillInterval"`
	FillMode     string  `json:"fillMode"`
	FillValue    float64 `json:"fillValue"`
	Format       string  `json:"format"`
}

type SQLMacroEngine

type SQLMacroEngine interface {
	Interpolate(query *backend.DataQuery, timeRange backend.TimeRange, sql string) (string, error)
}

SQLMacroEngine interpolates macros into sql. It takes in the Query to have access to query context and timeRange to be able to generate queries that use from and to.

type SQLMacroEngineBase

type SQLMacroEngineBase struct{}

func NewSQLMacroEngineBase

func NewSQLMacroEngineBase() *SQLMacroEngineBase

func (*SQLMacroEngineBase) ReplaceAllStringSubmatchFunc

func (m *SQLMacroEngineBase) ReplaceAllStringSubmatchFunc(re *regexp.Regexp, str string, repl func([]string) string) string

type SqlQueryResultTransformer

type SqlQueryResultTransformer interface {
	// TransformQueryError transforms a query error.
	TransformQueryError(logger log.Logger, err error) error
	GetConverterList() []sqlutil.StringConverter
}

SqlQueryResultTransformer transforms a query result row to RowValues with proper types.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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