159 lines
3 KiB
Go
159 lines
3 KiB
Go
|
|
// Code generated by sqlc. DO NOT EDIT.
|
||
|
|
// versions:
|
||
|
|
// sqlc v1.29.0
|
||
|
|
// source: film.sql
|
||
|
|
|
||
|
|
package sqlc
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
)
|
||
|
|
|
||
|
|
const countFilms = `-- name: CountFilms :one
|
||
|
|
SELECT COUNT(*)
|
||
|
|
FROM film
|
||
|
|
`
|
||
|
|
|
||
|
|
func (q *Queries) CountFilms(ctx context.Context) (int64, error) {
|
||
|
|
row := q.db.QueryRowContext(ctx, countFilms)
|
||
|
|
var count int64
|
||
|
|
err := row.Scan(&count)
|
||
|
|
return count, err
|
||
|
|
}
|
||
|
|
|
||
|
|
const getFilm = `-- name: GetFilm :one
|
||
|
|
SELECT film_id,
|
||
|
|
title,
|
||
|
|
description,
|
||
|
|
release_year,
|
||
|
|
language_id,
|
||
|
|
original_language_id,
|
||
|
|
rental_duration,
|
||
|
|
rental_rate,
|
||
|
|
length,
|
||
|
|
replacement_cost,
|
||
|
|
rating,
|
||
|
|
special_features,
|
||
|
|
last_update
|
||
|
|
FROM film
|
||
|
|
WHERE film_id = ?
|
||
|
|
`
|
||
|
|
|
||
|
|
func (q *Queries) GetFilm(ctx context.Context, filmID int64) (Film, error) {
|
||
|
|
row := q.db.QueryRowContext(ctx, getFilm, filmID)
|
||
|
|
var i Film
|
||
|
|
err := row.Scan(
|
||
|
|
&i.FilmID,
|
||
|
|
&i.Title,
|
||
|
|
&i.Description,
|
||
|
|
&i.ReleaseYear,
|
||
|
|
&i.LanguageID,
|
||
|
|
&i.OriginalLanguageID,
|
||
|
|
&i.RentalDuration,
|
||
|
|
&i.RentalRate,
|
||
|
|
&i.Length,
|
||
|
|
&i.ReplacementCost,
|
||
|
|
&i.Rating,
|
||
|
|
&i.SpecialFeatures,
|
||
|
|
&i.LastUpdate,
|
||
|
|
)
|
||
|
|
return i, err
|
||
|
|
}
|
||
|
|
|
||
|
|
const listActorsByFilm = `-- name: ListActorsByFilm :many
|
||
|
|
SELECT a.actor_id, a.first_name, a.last_name, a.last_update
|
||
|
|
FROM actor a
|
||
|
|
JOIN film_actor fa ON fa.actor_id = a.actor_id
|
||
|
|
WHERE fa.film_id = ?
|
||
|
|
ORDER BY a.last_name ASC, a.first_name ASC
|
||
|
|
`
|
||
|
|
|
||
|
|
func (q *Queries) ListActorsByFilm(ctx context.Context, filmID int64) ([]Actor, error) {
|
||
|
|
rows, err := q.db.QueryContext(ctx, listActorsByFilm, filmID)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
defer rows.Close()
|
||
|
|
var items []Actor
|
||
|
|
for rows.Next() {
|
||
|
|
var i Actor
|
||
|
|
if err := rows.Scan(
|
||
|
|
&i.ActorID,
|
||
|
|
&i.FirstName,
|
||
|
|
&i.LastName,
|
||
|
|
&i.LastUpdate,
|
||
|
|
); err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
items = append(items, i)
|
||
|
|
}
|
||
|
|
if err := rows.Close(); err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
if err := rows.Err(); err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
return items, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
const listFilms = `-- name: ListFilms :many
|
||
|
|
SELECT film_id,
|
||
|
|
title,
|
||
|
|
description,
|
||
|
|
release_year,
|
||
|
|
language_id,
|
||
|
|
original_language_id,
|
||
|
|
rental_duration,
|
||
|
|
rental_rate,
|
||
|
|
length,
|
||
|
|
replacement_cost,
|
||
|
|
rating,
|
||
|
|
special_features,
|
||
|
|
last_update
|
||
|
|
FROM film
|
||
|
|
ORDER BY film_id ASC
|
||
|
|
LIMIT ? OFFSET ?
|
||
|
|
`
|
||
|
|
|
||
|
|
type ListFilmsParams struct {
|
||
|
|
Limit int64 `json:"limit"`
|
||
|
|
Offset int64 `json:"offset"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func (q *Queries) ListFilms(ctx context.Context, arg ListFilmsParams) ([]Film, error) {
|
||
|
|
rows, err := q.db.QueryContext(ctx, listFilms, arg.Limit, arg.Offset)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
defer rows.Close()
|
||
|
|
var items []Film
|
||
|
|
for rows.Next() {
|
||
|
|
var i Film
|
||
|
|
if err := rows.Scan(
|
||
|
|
&i.FilmID,
|
||
|
|
&i.Title,
|
||
|
|
&i.Description,
|
||
|
|
&i.ReleaseYear,
|
||
|
|
&i.LanguageID,
|
||
|
|
&i.OriginalLanguageID,
|
||
|
|
&i.RentalDuration,
|
||
|
|
&i.RentalRate,
|
||
|
|
&i.Length,
|
||
|
|
&i.ReplacementCost,
|
||
|
|
&i.Rating,
|
||
|
|
&i.SpecialFeatures,
|
||
|
|
&i.LastUpdate,
|
||
|
|
); err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
items = append(items, i)
|
||
|
|
}
|
||
|
|
if err := rows.Close(); err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
if err := rows.Err(); err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
return items, nil
|
||
|
|
}
|