349 lines
7.1 KiB
Go
349 lines
7.1 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, $2, $3, $4, COALESCE($5, 0), COALESCE($6, true))
|
|
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"`
|
|
Column5 interface{} `json:"column_5"`
|
|
Column6 interface{} `json:"column_6"`
|
|
}
|
|
|
|
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.Column5,
|
|
arg.Column6,
|
|
)
|
|
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 DeleteProgram = `-- name: DeleteProgram :one
|
|
DELETE FROM programs
|
|
WHERE id = $1
|
|
RETURNING
|
|
id,
|
|
course_id,
|
|
title,
|
|
description,
|
|
thumbnail,
|
|
display_order,
|
|
is_active
|
|
`
|
|
|
|
func (q *Queries) DeleteProgram(ctx context.Context, id int64) (Program, error) {
|
|
row := q.db.QueryRow(ctx, DeleteProgram, 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 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 GetProgramsByCourse = `-- name: GetProgramsByCourse :many
|
|
SELECT
|
|
COUNT(*) OVER () AS total_count,
|
|
id,
|
|
course_id,
|
|
title,
|
|
description,
|
|
thumbnail,
|
|
display_order,
|
|
is_active
|
|
FROM programs
|
|
WHERE course_id = $1
|
|
ORDER BY display_order ASC
|
|
`
|
|
|
|
type GetProgramsByCourseRow struct {
|
|
TotalCount int64 `json:"total_count"`
|
|
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) GetProgramsByCourse(ctx context.Context, courseID int64) ([]GetProgramsByCourseRow, error) {
|
|
rows, err := q.db.Query(ctx, GetProgramsByCourse, courseID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetProgramsByCourseRow
|
|
for rows.Next() {
|
|
var i GetProgramsByCourseRow
|
|
if err := rows.Scan(
|
|
&i.TotalCount,
|
|
&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 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 UpdateProgramFull = `-- name: UpdateProgramFull :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 UpdateProgramFullParams 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) UpdateProgramFull(ctx context.Context, arg UpdateProgramFullParams) (Program, error) {
|
|
row := q.db.QueryRow(ctx, UpdateProgramFull,
|
|
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
|
|
}
|
|
|
|
const UpdateProgramPartial = `-- name: UpdateProgramPartial :exec
|
|
UPDATE programs
|
|
SET
|
|
title = COALESCE($1, title),
|
|
description = COALESCE($2, description),
|
|
thumbnail = COALESCE($3, thumbnail),
|
|
display_order = COALESCE($4, display_order),
|
|
is_active = COALESCE($5, is_active)
|
|
WHERE id = $6
|
|
`
|
|
|
|
type UpdateProgramPartialParams struct {
|
|
Title string `json:"title"`
|
|
Description pgtype.Text `json:"description"`
|
|
Thumbnail pgtype.Text `json:"thumbnail"`
|
|
DisplayOrder int32 `json:"display_order"`
|
|
IsActive bool `json:"is_active"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateProgramPartial(ctx context.Context, arg UpdateProgramPartialParams) error {
|
|
_, err := q.db.Exec(ctx, UpdateProgramPartial,
|
|
arg.Title,
|
|
arg.Description,
|
|
arg.Thumbnail,
|
|
arg.DisplayOrder,
|
|
arg.IsActive,
|
|
arg.ID,
|
|
)
|
|
return err
|
|
}
|