From 38d8fc32d552a23863a63eecf56d25a948c9db9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20M=C3=BCller?= Date: Fri, 10 Nov 2023 22:40:03 +0100 Subject: [PATCH] explicitly format timestamps on db insert --- internal/pkg/db/queries.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/internal/pkg/db/queries.go b/internal/pkg/db/queries.go index 7af34227..bdcc14b5 100644 --- a/internal/pkg/db/queries.go +++ b/internal/pkg/db/queries.go @@ -7,6 +7,8 @@ import ( "github.com/jo-m/trainbot/internal/pkg/stitch" ) +const tsFormat = "2006-01-02 15:04:05.999999999Z07:00" + // InsertTrain inserts a new train sighting into the database. // Returns the db id of the new row. func InsertTrain(db *sqlx.DB, t stitch.Train, imgPath, gifPath string) (int64, error) { @@ -26,8 +28,8 @@ func InsertTrain(db *sqlx.DB, t stitch.Train, imgPath, gifPath string) (int64, e VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id;` err := db.Get(&id, q, - t.StartTS, - t.EndTS, + t.StartTS.Format(tsFormat), + t.EndTS.Format(tsFormat), t.NFrames, t.LengthPx, t.SpeedPxS, @@ -73,7 +75,7 @@ func SetUploaded(db *sqlx.DB, id int64) error { const q = ` UPDATE trains SET uploaded_at = ? WHERE id = ?; ` - _, err := db.Exec(q, time.Now(), id) + _, err := db.Exec(q, time.Now().Format(tsFormat), id) return err } @@ -129,7 +131,7 @@ func InsertTemp(db *sqlx.DB, ts time.Time, tempDegC float64) (int64, error) { VALUES (?, ?) RETURNING id;` err := db.Get(&id, q, - ts, tempDegC) + ts.Format(tsFormat), tempDegC) if err != nil { return 0, err }