214 lines
3.8 KiB
Go
214 lines
3.8 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,
|
|
is_active
|
|
)
|
|
VALUES (
|
|
$1, -- category_id
|
|
$2, -- title
|
|
$3, -- description
|
|
$4 -- is_active
|
|
)
|
|
RETURNING
|
|
id,
|
|
category_id,
|
|
title,
|
|
description,
|
|
is_active
|
|
`
|
|
|
|
type CreateCourseParams struct {
|
|
CategoryID int64 `json:"category_id"`
|
|
Title string `json:"title"`
|
|
Description pgtype.Text `json:"description"`
|
|
IsActive bool `json:"is_active"`
|
|
}
|
|
|
|
func (q *Queries) CreateCourse(ctx context.Context, arg CreateCourseParams) (Course, error) {
|
|
row := q.db.QueryRow(ctx, CreateCourse,
|
|
arg.CategoryID,
|
|
arg.Title,
|
|
arg.Description,
|
|
arg.IsActive,
|
|
)
|
|
var i Course
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CategoryID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.IsActive,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const DeactivateCourse = `-- name: DeactivateCourse :exec
|
|
UPDATE courses
|
|
SET is_active = FALSE
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeactivateCourse(ctx context.Context, id int64) error {
|
|
_, err := q.db.Exec(ctx, DeactivateCourse, id)
|
|
return err
|
|
}
|
|
|
|
const GetCourseByID = `-- name: GetCourseByID :one
|
|
SELECT
|
|
id,
|
|
category_id,
|
|
title,
|
|
description,
|
|
is_active
|
|
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,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const ListActiveCourses = `-- name: ListActiveCourses :many
|
|
SELECT
|
|
id,
|
|
category_id,
|
|
title,
|
|
description,
|
|
is_active
|
|
FROM courses
|
|
WHERE is_active = TRUE
|
|
ORDER BY id DESC
|
|
`
|
|
|
|
func (q *Queries) ListActiveCourses(ctx context.Context) ([]Course, error) {
|
|
rows, err := q.db.Query(ctx, ListActiveCourses)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Course
|
|
for rows.Next() {
|
|
var i Course
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.CategoryID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.IsActive,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const ListCoursesByCategory = `-- name: ListCoursesByCategory :many
|
|
SELECT
|
|
id,
|
|
category_id,
|
|
title,
|
|
description,
|
|
is_active
|
|
FROM courses
|
|
WHERE category_id = $1
|
|
AND is_active = TRUE
|
|
ORDER BY id DESC
|
|
`
|
|
|
|
func (q *Queries) ListCoursesByCategory(ctx context.Context, categoryID int64) ([]Course, error) {
|
|
rows, err := q.db.Query(ctx, ListCoursesByCategory, categoryID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Course
|
|
for rows.Next() {
|
|
var i Course
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.CategoryID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&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 :one
|
|
UPDATE courses
|
|
SET
|
|
category_id = $2,
|
|
title = $3,
|
|
description = $4,
|
|
is_active = $5
|
|
WHERE id = $1
|
|
RETURNING
|
|
id,
|
|
category_id,
|
|
title,
|
|
description,
|
|
is_active
|
|
`
|
|
|
|
type UpdateCourseParams struct {
|
|
ID int64 `json:"id"`
|
|
CategoryID int64 `json:"category_id"`
|
|
Title string `json:"title"`
|
|
Description pgtype.Text `json:"description"`
|
|
IsActive bool `json:"is_active"`
|
|
}
|
|
|
|
func (q *Queries) UpdateCourse(ctx context.Context, arg UpdateCourseParams) (Course, error) {
|
|
row := q.db.QueryRow(ctx, UpdateCourse,
|
|
arg.ID,
|
|
arg.CategoryID,
|
|
arg.Title,
|
|
arg.Description,
|
|
arg.IsActive,
|
|
)
|
|
var i Course
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CategoryID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.IsActive,
|
|
)
|
|
return i, err
|
|
}
|