Moved the webapp to a webpack with some typescript, updated server wtih new endpoints
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"database/sql"
|
||||
_ "github.com/Freeaqingme/golang-sql-driver-mysql"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
var ClimateDb *sql.DB
|
||||
@@ -66,10 +67,10 @@ func getLastSnapshotRecordFromDb() (*SnapshotRecord, error) {
|
||||
return &snapshotRecord, nil
|
||||
}
|
||||
|
||||
func getSnapshotRecordsFromDb(minuteAgo int) ([]*SnapshotRecord, error) {
|
||||
func getSnapshotRecordsFromDb(dateSince time.Time) ([]*SnapshotRecord, error) {
|
||||
snapshots := make([]*SnapshotRecord, 0)
|
||||
query := "SELECT `%s`, `%s`, `%s`, `%s`, `%s` FROM `snapshots` WHERE `%s` > date_sub(now(), interval %v minute) ORDER BY `id` DESC;"
|
||||
rows, err := ClimateDb.Query(fmt.Sprintf(query, "id", "temp", "humidity", "co2", "time", "time", minuteAgo))
|
||||
query := "SELECT `%s`, `%s`, `%s`, `%s`, `%s` FROM `snapshots` WHERE `%s` > %s ORDER BY `id` DESC;"
|
||||
rows, err := ClimateDb.Query(fmt.Sprintf(query, "id", "temp", "humidity", "co2", "time", "time", dateSince.String()))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("couldn't execute select query: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user