140 lines
3.4 KiB
Go
140 lines
3.4 KiB
Go
|
|
// Code generated by sqlc. DO NOT EDIT.
|
||
|
|
// versions:
|
||
|
|
// sqlc v1.29.0
|
||
|
|
// source: categories.sql
|
||
|
|
|
||
|
|
package sqlc
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
)
|
||
|
|
|
||
|
|
const countCategories = `-- name: CountCategories :one
|
||
|
|
SELECT COUNT(*) FROM category
|
||
|
|
`
|
||
|
|
|
||
|
|
func (q *Queries) CountCategories(ctx context.Context) (int64, error) {
|
||
|
|
row := q.db.QueryRowContext(ctx, countCategories)
|
||
|
|
var count int64
|
||
|
|
err := row.Scan(&count)
|
||
|
|
return count, err
|
||
|
|
}
|
||
|
|
|
||
|
|
const countFilmsByCategoryName = `-- name: CountFilmsByCategoryName :one
|
||
|
|
SELECT COUNT(*)
|
||
|
|
FROM film f
|
||
|
|
JOIN film_category fc ON fc.film_id = f.film_id
|
||
|
|
JOIN category c ON c.category_id = fc.category_id
|
||
|
|
WHERE UPPER(c.name) = UPPER(?)
|
||
|
|
`
|
||
|
|
|
||
|
|
func (q *Queries) CountFilmsByCategoryName(ctx context.Context, upper string) (int64, error) {
|
||
|
|
row := q.db.QueryRowContext(ctx, countFilmsByCategoryName, upper)
|
||
|
|
var count int64
|
||
|
|
err := row.Scan(&count)
|
||
|
|
return count, err
|
||
|
|
}
|
||
|
|
|
||
|
|
const getCategory = `-- name: GetCategory :one
|
||
|
|
SELECT category_id, name, last_update
|
||
|
|
FROM category
|
||
|
|
WHERE category_id = ?
|
||
|
|
`
|
||
|
|
|
||
|
|
func (q *Queries) GetCategory(ctx context.Context, categoryID int64) (Category, error) {
|
||
|
|
row := q.db.QueryRowContext(ctx, getCategory, categoryID)
|
||
|
|
var i Category
|
||
|
|
err := row.Scan(&i.CategoryID, &i.Name, &i.LastUpdate)
|
||
|
|
return i, err
|
||
|
|
}
|
||
|
|
|
||
|
|
const listCategories = `-- name: ListCategories :many
|
||
|
|
SELECT category_id, name, last_update
|
||
|
|
FROM category
|
||
|
|
ORDER BY category_id ASC
|
||
|
|
LIMIT ? OFFSET ?
|
||
|
|
`
|
||
|
|
|
||
|
|
type ListCategoriesParams struct {
|
||
|
|
Limit int64 `json:"limit"`
|
||
|
|
Offset int64 `json:"offset"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func (q *Queries) ListCategories(ctx context.Context, arg ListCategoriesParams) ([]Category, error) {
|
||
|
|
rows, err := q.db.QueryContext(ctx, listCategories, arg.Limit, arg.Offset)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
defer rows.Close()
|
||
|
|
var items []Category
|
||
|
|
for rows.Next() {
|
||
|
|
var i Category
|
||
|
|
if err := rows.Scan(&i.CategoryID, &i.Name, &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 listFilmsByCategoryName = `-- name: ListFilmsByCategoryName :many
|
||
|
|
SELECT f.film_id, f.title, f.description, f.release_year, f.language_id,
|
||
|
|
f.original_language_id, f.rental_duration, f.rental_rate, f.length,
|
||
|
|
f.replacement_cost, f.rating, f.special_features, f.last_update
|
||
|
|
FROM film f
|
||
|
|
JOIN film_category fc ON fc.film_id = f.film_id
|
||
|
|
JOIN category c ON c.category_id = fc.category_id
|
||
|
|
WHERE UPPER(c.name) = UPPER(?)
|
||
|
|
ORDER BY f.film_id ASC
|
||
|
|
LIMIT ? OFFSET ?
|
||
|
|
`
|
||
|
|
|
||
|
|
type ListFilmsByCategoryNameParams struct {
|
||
|
|
UPPER string `json:"UPPER"`
|
||
|
|
Limit int64 `json:"limit"`
|
||
|
|
Offset int64 `json:"offset"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func (q *Queries) ListFilmsByCategoryName(ctx context.Context, arg ListFilmsByCategoryNameParams) ([]Film, error) {
|
||
|
|
rows, err := q.db.QueryContext(ctx, listFilmsByCategoryName, arg.UPPER, 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
|
||
|
|
}
|