canape/backend/models/imdb_ratings.go
Grégoire Delattre 09eb97b235
All checks were successful
continuous-integration/drone/push Build is passing
Remove unused stuff and check more errors
All the things fixed where reported by golangci-lint.
2020-03-01 16:20:06 +01:00

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
}