From 3c5e31b25a53268b413bc1e511b7486a2a1c80b9 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Wed, 8 Sep 2021 15:23:50 +0200 Subject: Renamed TrainStop to simply Stop --- pkg/database/train_stop.go | 47 ---------------------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 pkg/database/train_stop.go (limited to 'pkg/database/train_stop.go') diff --git a/pkg/database/train_stop.go b/pkg/database/train_stop.go deleted file mode 100644 index ee7be00..0000000 --- a/pkg/database/train_stop.go +++ /dev/null @@ -1,47 +0,0 @@ -package database - -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 := ` - INSERT INTO train_stops - (id, name) - VALUES - ($1, $2);` - tx, err := env.db.Begin() - if err != nil { - return newTransactionError("Could not Begin()", err) - } - _, err = tx.Exec(pre_query) - if err != nil { - tx.Rollback() - return newQueryError("Could not run database query: most likely the schema is corrupted", err) - } - for i := 0; i < len(trainStops); i++ { - _, err = tx.Exec( - query, - trainStops[i].Id, - trainStops[i].Name, - ) - if err != nil { - tx.Rollback() - return newQueryError("Could not run database query", err) - } - } - if err := tx.Commit(); err != nil { - return newTransactionError("Could not commit transaction", err) - } - return nil -} -- cgit v1.2.3