All checks were successful
continuous-integration/drone/push Build is passing
All the things fixed where reported by golangci-lint.
31 lines
727 B
Go
31 lines
727 B
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
)
|
|
|
|
const (
|
|
upsertRatingQuery = `INSERT INTO imdb_ratings (imdb_id, rating, votes) VALUES (:imdb_id, :rating, :votes)
|
|
ON CONFLICT (imdb_id)
|
|
DO UPDATE
|
|
SET imdb_id=:imdb_id, rating=:rating, votes=:votes
|
|
RETURNING imdb_id;`
|
|
)
|
|
|
|
// ImdbRating represents the ImdbRating in the DB
|
|
type ImdbRating struct {
|
|
ImdbID string `db:"imdb_id"`
|
|
Rating float32 `db:"rating"`
|
|
Votes int `db:"votes"`
|
|
Created time.Time `db:"created_at"`
|
|
Updated time.Time `db:"updated_at"`
|
|
}
|
|
|
|
// TxUpsertImdbRating upsert a ImdbRating in a transaction
|
|
func TxUpsertImdbRating(t *sqlx.Tx, rating *ImdbRating) error {
|
|
_, err := t.NamedExec(upsertRatingQuery, rating)
|
|
return err
|
|
}
|