Refactor setting fillmode

This adds SetupFillmode to the tsdb package to be used by the sql
datasources.
This commit is contained in:
Sven Klemm
2018-08-12 10:51:58 +02:00
parent 1f88bfd2bc
commit d81a23becf
4 changed files with 30 additions and 46 deletions
+21
View File
@@ -6,6 +6,7 @@ import (
"database/sql"
"fmt"
"math"
"strconv"
"strings"
"sync"
"time"
@@ -568,3 +569,23 @@ func ConvertSqlValueColumnToFloat(columnName string, columnValue interface{}) (n
return value, nil
}
func SetupFillmode(query *Query, interval time.Duration, fillmode string) error {
query.Model.Set("fill", true)
query.Model.Set("fillInterval", interval.Seconds())
switch fillmode {
case "NULL":
query.Model.Set("fillMode", "null")
case "previous":
query.Model.Set("fillMode", "previous")
default:
query.Model.Set("fillMode", "value")
floatVal, err := strconv.ParseFloat(fillmode, 64)
if err != nil {
return fmt.Errorf("error parsing fill value %v", fillmode)
}
query.Model.Set("fillValue", floatVal)
}
return nil
}