sqleng

package
v0.0.85-test Latest Latest
Warning

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

Go to latest
Published: May 8, 2023 License: AGPL-3.0 Imports: 19 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 = errors.New("failed to connect to server - please inspect Grafana server log for details")
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.

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(config DataPluginConfiguration, queryResultTransformer SqlQueryResultTransformer,
	macroEngine SQLMacroEngine, log log.Logger) (*DataSourceHandler, error)

func (*DataSourceHandler) Dispose

func (e *DataSourceHandler) Dispose()

func (*DataSourceHandler) QueryData

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 JsonData

type JsonData struct {
	MaxOpenConns        int    `json:"maxOpenConns"`
	MaxIdleConns        int    `json:"maxIdleConns"`
	ConnMaxLifetime     int    `json:"connMaxLifetime"`
	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"`
}

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(err error) error
	GetConverterList() []sqlutil.StringConverter
}

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

Jump to

Keyboard shortcuts

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