172 lines
3.7 KiB
Go
172 lines
3.7 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: courses.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const CreateCourse = `-- name: CreateCourse :one
|
|
INSERT INTO courses (
|
|
category_id,
|
|
title,
|
|
description,
|
|
thumbnail,
|
|
is_active
|
|
)
|
|
VALUES ($1, $2, $3, $4, COALESCE($5, true))
|
|
RETURNING id, category_id, title, description, is_active, thumbnail
|
|
`
|
|
|
|
type CreateCourseParams struct {
|
|
CategoryID int64 `json:"category_id"`
|
|
Title string `json:"title"`
|
|
Description pgtype.Text `json:"description"`
|
|
Thumbnail pgtype.Text `json:"thumbnail"`
|
|
Column5 interface{} `json:"column_5"`
|
|
}
|
|
|
|
func (q *Queries) CreateCourse(ctx context.Context, arg CreateCourseParams) (Course, error) {
|
|
row := q.db.QueryRow(ctx, CreateCourse,
|
|
arg.CategoryID,
|
|
arg.Title,
|
|
arg.Description,
|
|
arg.Thumbnail,
|
|
arg.Column5,
|
|
)
|
|
var i Course
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CategoryID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.IsActive,
|
|
&i.Thumbnail,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const DeleteCourse = `-- name: DeleteCourse :exec
|
|
DELETE FROM courses
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteCourse(ctx context.Context, id int64) error {
|
|
_, err := q.db.Exec(ctx, DeleteCourse, id)
|
|
return err
|
|
}
|
|
|
|
const GetCourseByID = `-- name: GetCourseByID :one
|
|
SELECT id, category_id, title, description, is_active, thumbnail
|
|
FROM courses
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetCourseByID(ctx context.Context, id int64) (Course, error) {
|
|
row := q.db.QueryRow(ctx, GetCourseByID, id)
|
|
var i Course
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CategoryID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.IsActive,
|
|
&i.Thumbnail,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const GetCoursesByCategory = `-- name: GetCoursesByCategory :many
|
|
SELECT
|
|
COUNT(*) OVER () AS total_count,
|
|
id,
|
|
category_id,
|
|
title,
|
|
description,
|
|
thumbnail,
|
|
is_active
|
|
FROM courses
|
|
WHERE category_id = $1
|
|
ORDER BY id DESC
|
|
LIMIT $3::INT
|
|
OFFSET $2::INT
|
|
`
|
|
|
|
type GetCoursesByCategoryParams struct {
|
|
CategoryID int64 `json:"category_id"`
|
|
Offset pgtype.Int4 `json:"offset"`
|
|
Limit pgtype.Int4 `json:"limit"`
|
|
}
|
|
|
|
type GetCoursesByCategoryRow struct {
|
|
TotalCount int64 `json:"total_count"`
|
|
ID int64 `json:"id"`
|
|
CategoryID int64 `json:"category_id"`
|
|
Title string `json:"title"`
|
|
Description pgtype.Text `json:"description"`
|
|
Thumbnail pgtype.Text `json:"thumbnail"`
|
|
IsActive bool `json:"is_active"`
|
|
}
|
|
|
|
func (q *Queries) GetCoursesByCategory(ctx context.Context, arg GetCoursesByCategoryParams) ([]GetCoursesByCategoryRow, error) {
|
|
rows, err := q.db.Query(ctx, GetCoursesByCategory, arg.CategoryID, arg.Offset, arg.Limit)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetCoursesByCategoryRow
|
|
for rows.Next() {
|
|
var i GetCoursesByCategoryRow
|
|
if err := rows.Scan(
|
|
&i.TotalCount,
|
|
&i.ID,
|
|
&i.CategoryID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.Thumbnail,
|
|
&i.IsActive,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const UpdateCourse = `-- name: UpdateCourse :exec
|
|
UPDATE courses
|
|
SET
|
|
title = COALESCE($1, title),
|
|
description = COALESCE($2, description),
|
|
thumbnail = COALESCE($3, thumbnail),
|
|
is_active = COALESCE($4, is_active)
|
|
WHERE id = $5
|
|
`
|
|
|
|
type UpdateCourseParams struct {
|
|
Title string `json:"title"`
|
|
Description pgtype.Text `json:"description"`
|
|
Thumbnail pgtype.Text `json:"thumbnail"`
|
|
IsActive bool `json:"is_active"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateCourse(ctx context.Context, arg UpdateCourseParams) error {
|
|
_, err := q.db.Exec(ctx, UpdateCourse,
|
|
arg.Title,
|
|
arg.Description,
|
|
arg.Thumbnail,
|
|
arg.IsActive,
|
|
arg.ID,
|
|
)
|
|
return err
|
|
}
|