0.2.4 EstVeJurnah gota get it to return its id tho nut other than that diz good
This commit is contained in:
38
database/EstimatedVehicleJourney.go
Normal file
38
database/EstimatedVehicleJourney.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func InsertOrUpdateEstimatedVehicleJourney(db *sql.DB, values []interface{}) error {
|
||||
query := `
|
||||
INSERT INTO estimatedvehiclejourney (servicedelivery, recordedattime, lineref, directionref, datasource, datedvehiclejourneyref, vehiclemode, dataframeref, originref, destinationref, operatorref, vehicleref, cancellation, other)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)
|
||||
ON CONFLICT (lineref, directionref, datasource, datedvehiclejourneyref)
|
||||
DO UPDATE SET
|
||||
servicedelivery = EXCLUDED.servicedelivery,
|
||||
recordedattime = EXCLUDED.recordedattime,
|
||||
vehiclemode = COALESCE(EXCLUDED.vehiclemode, estimatedvehiclejourney.vehiclemode),
|
||||
dataframeref = COALESCE(EXCLUDED.dataframeref, estimatedvehiclejourney.dataframeref),
|
||||
originref = COALESCE(EXCLUDED.originref, estimatedvehiclejourney.originref),
|
||||
destinationref = COALESCE(EXCLUDED.destinationref, estimatedvehiclejourney.destinationref),
|
||||
operatorref = COALESCE(EXCLUDED.operatorref, estimatedvehiclejourney.operatorref),
|
||||
vehicleref = COALESCE(EXCLUDED.vehicleref, estimatedvehiclejourney.vehicleref),
|
||||
cancellation = COALESCE(EXCLUDED.cancellation, estimatedvehiclejourney.cancellation),
|
||||
other = COALESCE(EXCLUDED.other, estimatedvehiclejourney.other);
|
||||
`
|
||||
|
||||
stmt, err := db.Prepare(query)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error preparing statement: %v", err)
|
||||
}
|
||||
defer stmt.Close()
|
||||
|
||||
_, err = stmt.Exec(values...)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error executing statement: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -10,11 +10,10 @@ func InsertServiceDelivery(db *sql.DB, responseTimestamp string, recordedAtTime
|
||||
var id int
|
||||
|
||||
err := db.QueryRow("INSERT INTO public.ServiceDelivery (ResponseTimestamp, RecordedAtTime) VALUES ($1, $2) RETURNING ID", responseTimestamp, recordedAtTime).Scan(&id)
|
||||
fmt.Println(err)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return 0, err
|
||||
}
|
||||
fmt.Println("ID:", id)
|
||||
fmt.Println("ServiceDelivery inserted successfully!")
|
||||
fmt.Println("ServiceDelivery inserted successfully! (", id, ")")
|
||||
return id, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user