From e551390089d9dd54cdd6d73258d53d6f2ab48547 Mon Sep 17 00:00:00 2001 From: saji Date: Sun, 18 Feb 2024 13:40:41 -0600 Subject: [PATCH] wip: more fixes, figure out main problem --- internal/db/getters.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/internal/db/getters.go b/internal/db/getters.go index 6112e25..79dc9d5 100644 --- a/internal/db/getters.go +++ b/internal/db/getters.go @@ -16,20 +16,20 @@ type Datum struct { // GetValues queries the database for values in a given time range. // A value is a specific data point. For example, bms_measurement.current // would be a value. -func (tdb *TelemDb) GetValues(ctx context.Context, packetName, field string , start time.Time, +func (tdb *TelemDb) GetValues(ctx context.Context, packetName, field string, start time.Time, end time.Time) ([]Datum, error) { // this fragment uses json_extract from sqlite to get a single // nested value. const SqlFrag = ` SELECT datetime(ts /1000.0, 'unixepoch', 'subsec') as timestamp, - json_extract(data, ?) as val - FROM bus_events WHERE name IS ?; + json_extract(data, '$.' || ?) as val + FROM bus_events WHERE name IS ? AND timestamp IS NOT NULL ` + fmt.Print(start, end, packetName, field) - rows, err := tdb.db.QueryxContext(ctx, "'$.current'", packetName) + rows, err := tdb.db.QueryxContext(ctx, SqlFrag, field, packetName, start, end) if err != nil { - fmt.Print(err) return nil, err } defer rows.Close() @@ -38,11 +38,12 @@ func (tdb *TelemDb) GetValues(ctx context.Context, packetName, field string , st var d Datum err = rows.StructScan(&d) if err != nil { + fmt.Print(err) return data, err } data = append(data, d) } + fmt.Print(data) return data, nil } -