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

233 lines
4.7 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,
number_of_modules,
number_of_practices,
number_of_videos,
is_active
)
VALUES (
$1, -- program_id
$2, -- title
$3, -- description
$4, -- level_index
$5, -- number_of_modules
$6, -- number_of_practices
$7, -- number_of_videos
$8 -- is_active
)
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"`
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) CreateLevel(ctx context.Context, arg CreateLevelParams) (Level, error) {
row := q.db.QueryRow(ctx, CreateLevel,
arg.ProgramID,
arg.Title,
arg.Description,
arg.LevelIndex,
arg.NumberOfModules,
arg.NumberOfPractices,
arg.NumberOfVideos,
arg.IsActive,
)
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 DeactivateLevel = `-- name: DeactivateLevel :exec
UPDATE levels
SET is_active = FALSE
WHERE id = $1
`
func (q *Queries) DeactivateLevel(ctx context.Context, id int64) error {
_, err := q.db.Exec(ctx, DeactivateLevel, id)
return err
}
const GetLevelByID = `-- name: GetLevelByID :one
SELECT
id,
program_id,
title,
description,
level_index,
number_of_modules,
number_of_practices,
number_of_videos,
is_active
FROM levels
WHERE id = $1
`
func (q *Queries) GetLevelByID(ctx context.Context, id int64) (Level, error) {
row := q.db.QueryRow(ctx, GetLevelByID, id)
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 ListLevelsByProgram = `-- name: ListLevelsByProgram :many
SELECT
id,
program_id,
title,
description,
level_index,
number_of_modules,
number_of_practices,
number_of_videos,
is_active
FROM levels
WHERE program_id = $1
AND is_active = TRUE
ORDER BY level_index ASC
`
func (q *Queries) ListLevelsByProgram(ctx context.Context, programID int64) ([]Level, error) {
rows, err := q.db.Query(ctx, ListLevelsByProgram, programID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Level
for rows.Next() {
var i Level
if err := rows.Scan(
&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 UpdateLevel = `-- name: UpdateLevel :one
UPDATE levels
SET
title = $2,
description = $3,
level_index = $4,
number_of_modules = $5,
number_of_practices = $6,
number_of_videos = $7,
is_active = $8
WHERE id = $1
RETURNING
id,
program_id,
title,
description,
level_index,
number_of_modules,
number_of_practices,
number_of_videos,
is_active
`
type UpdateLevelParams struct {
ID int64 `json:"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) UpdateLevel(ctx context.Context, arg UpdateLevelParams) (Level, error) {
row := q.db.QueryRow(ctx, UpdateLevel,
arg.ID,
arg.Title,
arg.Description,
arg.LevelIndex,
arg.NumberOfModules,
arg.NumberOfPractices,
arg.NumberOfVideos,
arg.IsActive,
)
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
}