From cf7f851a5f47bab8a979135c834dae9ead63a042 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Tue, 7 Sep 2021 17:32:47 +0200 Subject: Added logic to fetch train stops data if missing when starting the webserver --- pkg/database/train_stop.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'pkg/database/train_stop.go') diff --git a/pkg/database/train_stop.go b/pkg/database/train_stop.go index 452f6c3..ee7be00 100644 --- a/pkg/database/train_stop.go +++ b/pkg/database/train_stop.go @@ -4,6 +4,15 @@ import ( "git.adyxax.org/adyxax/trains/pkg/model" ) +func (env *DBEnv) CountTrainStops() (i int, err error) { + query := `SELECT count(*) from train_stops;` + err = env.db.QueryRow(query).Scan(&i) + if err != nil { + return 0, newQueryError("Could not run database query: most likely the schema is corrupted", err) + } + return +} + func (env *DBEnv) ReplaceAndImportTrainStops(trainStops []model.TrainStop) error { pre_query := `DELETE FROM train_stops;` query := ` @@ -28,7 +37,7 @@ func (env *DBEnv) ReplaceAndImportTrainStops(trainStops []model.TrainStop) error ) if err != nil { tx.Rollback() - return newQueryError("Could not run database query: ", err) + return newQueryError("Could not run database query", err) } } if err := tx.Commit(); err != nil { -- cgit v1.2.3