77 "fmt"
88 "net/http"
99 "sync"
10- "time"
1110
1211 "github.com/grafana/grafana-plugin-sdk-go/backend"
1312 "github.com/grafana/grafana-plugin-sdk-go/backend/instancemgmt"
@@ -18,10 +17,11 @@ import (
1817type sqldatasource struct {
1918 Completable
2019
21- db * sql.DB
22- c Driver
23- settings backend.DataSourceInstanceSettings
24- timeout time.Duration
20+ db * sql.DB
21+ c Driver
22+
23+ driverSettings DriverSettings
24+ settings backend.DataSourceInstanceSettings
2525
2626 backend.CallResourceHandler
2727 CustomRoutes map [string ]func (http.ResponseWriter , * http.Request )
@@ -43,7 +43,7 @@ func (ds *sqldatasource) NewDatasource(settings backend.DataSourceInstanceSettin
4343 }
4444
4545 ds .CallResourceHandler = httpadapter .New (mux )
46- ds .timeout = ds .c .Timeout (settings )
46+ ds .driverSettings = ds .c .Settings (settings )
4747
4848 return ds , nil
4949}
@@ -103,13 +103,13 @@ func (ds *sqldatasource) handleQuery(ctx context.Context, req backend.DataQuery)
103103 }
104104
105105 // Apply the default FillMode, overwritting it if the query specifies it
106- fillMode := ds .c .FillMode ()
106+ fillMode := ds .driverSettings .FillMode
107107 if q .FillMissing != nil {
108108 fillMode = q .FillMissing
109109 }
110110
111- if ds .timeout != 0 {
112- tctx , cancel := context .WithTimeout (ctx , ds .timeout )
111+ if ds .driverSettings . Timeout != 0 {
112+ tctx , cancel := context .WithTimeout (ctx , ds .driverSettings . Timeout )
113113 defer cancel ()
114114
115115 ctx = tctx
@@ -119,15 +119,13 @@ func (ds *sqldatasource) handleQuery(ctx context.Context, req backend.DataQuery)
119119 // * Some datasources (snowflake) expire connections or have an authentication token that expires if not used in 1 or 4 hours.
120120 // Because the datasource driver does not include an option for permanent connections, we retry the connection
121121 // if the query fails. NOTE: this does not include some errors like "ErrNoRows"
122-
123- // This function will return an "ErrorTimeout" if the context's done channel receives data
124- res , err := queryContext (ctx , ds .db , ds .c .Converters (), fillMode , q )
122+ res , err := query (ctx , ds .db , ds .c .Converters (), fillMode , q )
125123 if err == nil {
126124 return res , nil
127125 }
128126
129127 if errors .Is (err , ErrorNoResults ) {
130- return nil , nil
128+ return res , nil
131129 }
132130
133131 if errors .Is (err , ErrorQuery ) {
@@ -136,7 +134,7 @@ func (ds *sqldatasource) handleQuery(ctx context.Context, req backend.DataQuery)
136134 return nil , err
137135 }
138136
139- return queryContext (ctx , ds .db , ds .c .Converters (), fillMode , q )
137+ return query (ctx , ds .db , ds .c .Converters (), fillMode , q )
140138 }
141139
142140 return nil , err
0 commit comments