Skip to content

Instantly share code, notes, and snippets.

@jayhuang75
Last active October 25, 2021 17:45
Show Gist options
  • Select an option

  • Save jayhuang75/334f3849f5f353952f0fe0a546f338e5 to your computer and use it in GitHub Desktop.

Select an option

Save jayhuang75/334f3849f5f353952f0fe0a546f338e5 to your computer and use it in GitHub Desktop.
go-train-delay-db-insert.go
func (db *DB) Insert(data []DelayDataSet) {
tx := db.Pool.MustBegin()
bar := processBar(int64(len(data)), "[db] inserting...")
for _, d := range data {
tx.MustExec(
"INSERT INTO delays (date, departure, depart_scheduled, destination, arrival_scheduled, delay) VALUES ($1, $2, $3, $4, $5, $6) ON CONFLICT (date) DO NOTHING",
d.Date,
d.Departure.Station,
d.Departure.Scheduled,
d.Destination.Station,
d.Destination.Scheduled,
d.Mins,
)
bar.Add(1)
time.Sleep(40 * time.Millisecond)
}
tx.Commit()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment