wip: more fixes, figure out main problem

This commit is contained in:
saji 2024-02-18 13:40:41 -06:00
parent 8af1b725d1
commit e551390089

View file

@ -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
}