Yimaru-BackEnd/gen/db/program_levels.sql.go

189 lines
4.5 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: program_levels.sql
package dbgen
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const CreateLevel = `-- name: CreateLevel :one
INSERT INTO levels (
program_id,
title,
description,
level_index,
is_active
)
VALUES ($1, $2, $3, $4, COALESCE($5, true))
RETURNING id, program_id, title, description, level_index, number_of_modules, number_of_practices, number_of_videos, is_active
`
type CreateLevelParams struct {
ProgramID int64 `json:"program_id"`
Title string `json:"title"`
Description pgtype.Text `json:"description"`
LevelIndex int32 `json:"level_index"`
Column5 interface{} `json:"column_5"`
}
func (q *Queries) CreateLevel(ctx context.Context, arg CreateLevelParams) (Level, error) {
row := q.db.QueryRow(ctx, CreateLevel,
arg.ProgramID,
arg.Title,
arg.Description,
arg.LevelIndex,
arg.Column5,
)
var i Level
err := row.Scan(
&i.ID,
&i.ProgramID,
&i.Title,
&i.Description,
&i.LevelIndex,
&i.NumberOfModules,
&i.NumberOfPractices,
&i.NumberOfVideos,
&i.IsActive,
)
return i, err
}
const DeleteLevel = `-- name: DeleteLevel :exec
DELETE FROM levels
WHERE id = $1
`
func (q *Queries) DeleteLevel(ctx context.Context, id int64) error {
_, err := q.db.Exec(ctx, DeleteLevel, id)
return err
}
const GetLevelsByProgram = `-- name: GetLevelsByProgram :many
SELECT
COUNT(*) OVER () AS total_count,
id,
program_id,
title,
description,
level_index,
number_of_modules,
number_of_practices,
number_of_videos,
is_active
FROM levels
WHERE program_id = $1
ORDER BY level_index ASC
`
type GetLevelsByProgramRow struct {
TotalCount int64 `json:"total_count"`
ID int64 `json:"id"`
ProgramID int64 `json:"program_id"`
Title string `json:"title"`
Description pgtype.Text `json:"description"`
LevelIndex int32 `json:"level_index"`
NumberOfModules int32 `json:"number_of_modules"`
NumberOfPractices int32 `json:"number_of_practices"`
NumberOfVideos int32 `json:"number_of_videos"`
IsActive bool `json:"is_active"`
}
func (q *Queries) GetLevelsByProgram(ctx context.Context, programID int64) ([]GetLevelsByProgramRow, error) {
rows, err := q.db.Query(ctx, GetLevelsByProgram, programID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetLevelsByProgramRow
for rows.Next() {
var i GetLevelsByProgramRow
if err := rows.Scan(
&i.TotalCount,
&i.ID,
&i.ProgramID,
&i.Title,
&i.Description,
&i.LevelIndex,
&i.NumberOfModules,
&i.NumberOfPractices,
&i.NumberOfVideos,
&i.IsActive,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const IncrementLevelModuleCount = `-- name: IncrementLevelModuleCount :exec
UPDATE levels
SET number_of_modules = number_of_modules + 1
WHERE id = $1
`
func (q *Queries) IncrementLevelModuleCount(ctx context.Context, id int64) error {
_, err := q.db.Exec(ctx, IncrementLevelModuleCount, id)
return err
}
const IncrementLevelPracticeCount = `-- name: IncrementLevelPracticeCount :exec
UPDATE levels
SET number_of_practices = number_of_practices + 1
WHERE id = $1
`
func (q *Queries) IncrementLevelPracticeCount(ctx context.Context, id int64) error {
_, err := q.db.Exec(ctx, IncrementLevelPracticeCount, id)
return err
}
const IncrementLevelVideoCount = `-- name: IncrementLevelVideoCount :exec
UPDATE levels
SET number_of_videos = number_of_videos + 1
WHERE id = $1
`
func (q *Queries) IncrementLevelVideoCount(ctx context.Context, id int64) error {
_, err := q.db.Exec(ctx, IncrementLevelVideoCount, id)
return err
}
const UpdateLevel = `-- name: UpdateLevel :exec
UPDATE levels
SET
title = COALESCE($1, title),
description = COALESCE($2, description),
level_index = COALESCE($3, level_index),
is_active = COALESCE($4, is_active)
WHERE id = $5
`
type UpdateLevelParams struct {
Title string `json:"title"`
Description pgtype.Text `json:"description"`
LevelIndex int32 `json:"level_index"`
IsActive bool `json:"is_active"`
ID int64 `json:"id"`
}
func (q *Queries) UpdateLevel(ctx context.Context, arg UpdateLevelParams) error {
_, err := q.db.Exec(ctx, UpdateLevel,
arg.Title,
arg.Description,
arg.LevelIndex,
arg.IsActive,
arg.ID,
)
return err
}