Categorygithub.com/grafana/sqlds/v2
modulepackage
2.7.2
Repository: https://github.com/grafana/sqlds.git
Documentation: pkg.go.dev

# README

Build Status

sqlds

sqlds stands for SQL Datasource.

Most SQL-driven datasources, like Postgres, MySQL, and MSSQL share extremely similar codebases.

The sqlds package is intended to remove the repetition of these datasources and centralize the datasource logic. The only thing that the datasources themselves should have to define is connecting to the database, and what driver to use, and the plugin frontend.

Usage

ds := sqlds.NewDatasource(&myDatasource{})
if err := datasource.Manage("my-datasource", ds.NewDatasource, datasource.ManageOpts{}); err != nil {
  log.DefaultLogger.Error(err.Error())
  os.Exit(1)
}

Standardization

Macros

The sqlds package defines a set of default macros:

  • $__timeFilter(time_column): Filters by timestamp using the query period. Resolves to: time >= '0001-01-01T00:00:00Z' AND time <= '0001-01-01T00:00:00Z'
  • $__timeFrom(time_column): Filters by timestamp using the start point of the query period. Resolves to time >= '0001-01-01T00:00:00Z'
  • $__timeTo(time_column): Filters by timestamp using the end point of the query period. Resolves to time <= '0001-01-01T00:00:00Z'
  • $__timeGroup(time_column, period): To group times based on a period. Resolves to (minute example): "datepart(year, time), datepart(month, time)'"
  • $__table: Returns the table configured in the query.
  • $__column: Returns the column configured in the query.

# Packages

No description provided by the author
No description provided by the author

# Functions

CreateData will create a "table" (csv file) in the data folder that can be queried with SQL.
Create will create a "table" (csv file) in the data folder that can be queried with SQL.
GetQuery returns a Query object given a backend.DataQuery using json.Unmarshal.
Interpolate returns an interpolated query string given a backend.DataQuery.
NewDatasource initializes the Datasource wrapper and instance manager.
No description provided by the author
No description provided by the author
QueryDB sends the query to the connection and converts the rows to a dataframe.

# Constants

FormatOptionLogs sets the preferred visualization to logs.
FormatOptionTable formats the query results as a table using "LongToWide".
FormatOptionTimeSeries formats the query results as a timeseries using "WideToLong".
FormatOptionsTrace sets the preferred visualization to trace.
MockDataFolder is the default folder that will contain data files.

# Variables

No description provided by the author
ErrorBadArgumentCount is returned from macros when the wrong number of arguments were provided.
ErrorBadDatasource is returned if the data source could not be asserted to the correct type (this should basically never happen?).
ErrorJSON is returned when json.Unmarshal fails.
No description provided by the author
No description provided by the author
ErrorNoResults is returned if there were no results returned.
ErrorNotImplemented is returned if the function is not implemented by the provided Driver (the Completable pointer is nil).
ErrorQuery is returned when the query could not complete / execute.
ErrorTimeout is returned if the query has timed out.
ErrorWrongOptions when trying to parse Options with a invalid JSON.
No description provided by the author
Deprecated: ErrorMissingDBConnection should be used instead.
Deprecated: ErrorMissingMultipleConnectionsConfig should be used instead.

# Structs

No description provided by the author
No description provided by the author
Query is the model that represents the query that users submit from the panel / queryeditor.
No description provided by the author
No description provided by the author
SQLMock connects to a local folder with csv files.

# Interfaces

Completable will be used to autocomplete Tables Schemas and Columns for SQL languages.
Connection represents a SQL connection and is satisfied by the *sql.DB type For now, we only add the functions that we need / actively use.
Driver is a simple interface that defines how to connect to a backend SQL datasource Plugin creators will need to implement this in order to create a managed datasource.
QueryArgSetter is an additional interface that could be implemented by driver.
QueryMutator is an additional interface that could be implemented by driver.
ResponseMutator is an additional interface that could be implemented by driver.

# Type aliases

FormatQueryOption defines how the user has chosen to represent the data.
MacroFunc defines a signature for applying a query macro Query macro implementations are defined by users / consumers of this package.
Macros is a list of MacroFuncs.
Options are used to query schemas, tables and columns.