248 lines
4.6 KiB
Go
248 lines
4.6 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: course_programs.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const CreateProgram = `-- name: CreateProgram :one
|
|
INSERT INTO programs (
|
|
course_id,
|
|
title,
|
|
description,
|
|
thumbnail,
|
|
display_order,
|
|
is_active
|
|
)
|
|
VALUES (
|
|
$1, -- course_id
|
|
$2, -- title
|
|
$3, -- description
|
|
$4, -- thumbnail
|
|
$5, -- display_order
|
|
$6 -- is_active
|
|
)
|
|
RETURNING
|
|
id,
|
|
course_id,
|
|
title,
|
|
description,
|
|
thumbnail,
|
|
display_order,
|
|
is_active
|
|
`
|
|
|
|
type CreateProgramParams struct {
|
|
CourseID int64 `json:"course_id"`
|
|
Title string `json:"title"`
|
|
Description pgtype.Text `json:"description"`
|
|
Thumbnail pgtype.Text `json:"thumbnail"`
|
|
DisplayOrder int32 `json:"display_order"`
|
|
IsActive bool `json:"is_active"`
|
|
}
|
|
|
|
func (q *Queries) CreateProgram(ctx context.Context, arg CreateProgramParams) (Program, error) {
|
|
row := q.db.QueryRow(ctx, CreateProgram,
|
|
arg.CourseID,
|
|
arg.Title,
|
|
arg.Description,
|
|
arg.Thumbnail,
|
|
arg.DisplayOrder,
|
|
arg.IsActive,
|
|
)
|
|
var i Program
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CourseID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.Thumbnail,
|
|
&i.DisplayOrder,
|
|
&i.IsActive,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const DeactivateProgram = `-- name: DeactivateProgram :exec
|
|
UPDATE programs
|
|
SET is_active = FALSE
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeactivateProgram(ctx context.Context, id int64) error {
|
|
_, err := q.db.Exec(ctx, DeactivateProgram, id)
|
|
return err
|
|
}
|
|
|
|
const GetProgramByID = `-- name: GetProgramByID :one
|
|
SELECT
|
|
id,
|
|
course_id,
|
|
title,
|
|
description,
|
|
thumbnail,
|
|
display_order,
|
|
is_active
|
|
FROM programs
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetProgramByID(ctx context.Context, id int64) (Program, error) {
|
|
row := q.db.QueryRow(ctx, GetProgramByID, id)
|
|
var i Program
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CourseID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.Thumbnail,
|
|
&i.DisplayOrder,
|
|
&i.IsActive,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const ListActivePrograms = `-- name: ListActivePrograms :many
|
|
SELECT
|
|
id,
|
|
course_id,
|
|
title,
|
|
description,
|
|
thumbnail,
|
|
display_order,
|
|
is_active
|
|
FROM programs
|
|
WHERE is_active = TRUE
|
|
ORDER BY display_order ASC
|
|
`
|
|
|
|
func (q *Queries) ListActivePrograms(ctx context.Context) ([]Program, error) {
|
|
rows, err := q.db.Query(ctx, ListActivePrograms)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Program
|
|
for rows.Next() {
|
|
var i Program
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.CourseID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.Thumbnail,
|
|
&i.DisplayOrder,
|
|
&i.IsActive,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const ListProgramsByCourse = `-- name: ListProgramsByCourse :many
|
|
SELECT
|
|
id,
|
|
course_id,
|
|
title,
|
|
description,
|
|
thumbnail,
|
|
display_order,
|
|
is_active
|
|
FROM programs
|
|
WHERE course_id = $1
|
|
AND is_active = TRUE
|
|
ORDER BY display_order ASC, id ASC
|
|
`
|
|
|
|
func (q *Queries) ListProgramsByCourse(ctx context.Context, courseID int64) ([]Program, error) {
|
|
rows, err := q.db.Query(ctx, ListProgramsByCourse, courseID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Program
|
|
for rows.Next() {
|
|
var i Program
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.CourseID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.Thumbnail,
|
|
&i.DisplayOrder,
|
|
&i.IsActive,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const UpdateProgram = `-- name: UpdateProgram :one
|
|
UPDATE programs
|
|
SET
|
|
course_id = $2,
|
|
title = $3,
|
|
description = $4,
|
|
thumbnail = $5,
|
|
display_order = $6,
|
|
is_active = $7
|
|
WHERE id = $1
|
|
RETURNING
|
|
id,
|
|
course_id,
|
|
title,
|
|
description,
|
|
thumbnail,
|
|
display_order,
|
|
is_active
|
|
`
|
|
|
|
type UpdateProgramParams struct {
|
|
ID int64 `json:"id"`
|
|
CourseID int64 `json:"course_id"`
|
|
Title string `json:"title"`
|
|
Description pgtype.Text `json:"description"`
|
|
Thumbnail pgtype.Text `json:"thumbnail"`
|
|
DisplayOrder int32 `json:"display_order"`
|
|
IsActive bool `json:"is_active"`
|
|
}
|
|
|
|
func (q *Queries) UpdateProgram(ctx context.Context, arg UpdateProgramParams) (Program, error) {
|
|
row := q.db.QueryRow(ctx, UpdateProgram,
|
|
arg.ID,
|
|
arg.CourseID,
|
|
arg.Title,
|
|
arg.Description,
|
|
arg.Thumbnail,
|
|
arg.DisplayOrder,
|
|
arg.IsActive,
|
|
)
|
|
var i Program
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CourseID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.Thumbnail,
|
|
&i.DisplayOrder,
|
|
&i.IsActive,
|
|
)
|
|
return i, err
|
|
}
|