Skip to content

Commit a649fed

Browse files
authored
QueryMutator interface for driver (#87)
1 parent f35c5a6 commit a649fed

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

datasource.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ func (ds *SQLDatasource) getDBConnectionFromQuery(q *Query, datasourceUID string
179179

180180
// handleQuery will call query, and attempt to reconnect if the query failed
181181
func (ds *SQLDatasource) handleQuery(ctx context.Context, req backend.DataQuery, datasourceUID string) (data.Frames, error) {
182+
if queryMutator, ok := ds.c.(QueryMutator); ok {
183+
ctx, req = queryMutator.MutateQuery(ctx, req)
184+
}
185+
182186
// Convert the backend.DataQuery into a Query object
183187
q, err := GetQuery(req)
184188
if err != nil {

driver.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,9 @@ type Connection interface {
3838
PingContext(ctx context.Context) error
3939
QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
4040
}
41+
42+
// QueryMutator is an additional interface that could be implemented by driver.
43+
// This adds ability to the driver it can mutate query before run.
44+
type QueryMutator interface {
45+
MutateQuery(ctx context.Context, req backend.DataQuery) (context.Context, backend.DataQuery)
46+
}

0 commit comments

Comments
 (0)