wip: more fixes, figure out main problem
This commit is contained in:
parent
8af1b725d1
commit
e551390089
|
@ -16,20 +16,20 @@ type Datum struct {
|
||||||
// GetValues queries the database for values in a given time range.
|
// GetValues queries the database for values in a given time range.
|
||||||
// A value is a specific data point. For example, bms_measurement.current
|
// A value is a specific data point. For example, bms_measurement.current
|
||||||
// would be a value.
|
// 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) {
|
end time.Time) ([]Datum, error) {
|
||||||
// this fragment uses json_extract from sqlite to get a single
|
// this fragment uses json_extract from sqlite to get a single
|
||||||
// nested value.
|
// nested value.
|
||||||
const SqlFrag = `
|
const SqlFrag = `
|
||||||
SELECT
|
SELECT
|
||||||
datetime(ts /1000.0, 'unixepoch', 'subsec') as timestamp,
|
datetime(ts /1000.0, 'unixepoch', 'subsec') as timestamp,
|
||||||
json_extract(data, ?) as val
|
json_extract(data, '$.' || ?) as val
|
||||||
FROM bus_events WHERE name IS ?;
|
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 {
|
if err != nil {
|
||||||
fmt.Print(err)
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
@ -38,11 +38,12 @@ func (tdb *TelemDb) GetValues(ctx context.Context, packetName, field string , st
|
||||||
var d Datum
|
var d Datum
|
||||||
err = rows.StructScan(&d)
|
err = rows.StructScan(&d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
fmt.Print(err)
|
||||||
return data, err
|
return data, err
|
||||||
}
|
}
|
||||||
data = append(data, d)
|
data = append(data, d)
|
||||||
}
|
}
|
||||||
|
fmt.Print(data)
|
||||||
|
|
||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue