-
Notifications
You must be signed in to change notification settings - Fork 12
/
driver.go
38 lines (33 loc) · 1.31 KB
/
driver.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package sqlds
import (
"context"
"database/sql"
"encoding/json"
"time"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/grafana/grafana-plugin-sdk-go/data/sqlutil"
)
type DriverSettings struct {
Timeout time.Duration
FillMode *data.FillMissing
Retries int
}
// 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
type Driver interface {
// Connect connects to the database. It does not need to call `db.Ping()`
Connect(backend.DataSourceInstanceSettings, json.RawMessage) (*sql.DB, error)
// Settings are read whenever the plugin is initialized, or after the data source settings are updated
Settings(backend.DataSourceInstanceSettings) DriverSettings
Macros() Macros
Converters() []sqlutil.Converter
}
// 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. Some other candidates for future use could include the ExecContext and BeginTxContext functions
type Connection interface {
Close() error
Ping() error
PingContext(ctx context.Context) error
QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
}