244 lines
5.8 KiB
Go
244 lines
5.8 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: exam_prep_unit_modules.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const ExamPrepCreateUnitModule = `-- name: ExamPrepCreateUnitModule :one
|
|
INSERT INTO exam_prep.unit_modules (unit_id, name, description, thumbnail, icon, sort_order)
|
|
SELECT
|
|
$1,
|
|
$2,
|
|
$3,
|
|
$4,
|
|
$5,
|
|
coalesce((
|
|
SELECT
|
|
max(m.sort_order)
|
|
FROM exam_prep.unit_modules m
|
|
WHERE
|
|
m.unit_id = $1), 0) + 1
|
|
RETURNING
|
|
id, unit_id, name, description, thumbnail, icon, sort_order, created_at, updated_at
|
|
`
|
|
|
|
type ExamPrepCreateUnitModuleParams struct {
|
|
UnitID int64 `json:"unit_id"`
|
|
Name string `json:"name"`
|
|
Description pgtype.Text `json:"description"`
|
|
Thumbnail pgtype.Text `json:"thumbnail"`
|
|
Icon pgtype.Text `json:"icon"`
|
|
}
|
|
|
|
func (q *Queries) ExamPrepCreateUnitModule(ctx context.Context, arg ExamPrepCreateUnitModuleParams) (ExamPrepUnitModule, error) {
|
|
row := q.db.QueryRow(ctx, ExamPrepCreateUnitModule,
|
|
arg.UnitID,
|
|
arg.Name,
|
|
arg.Description,
|
|
arg.Thumbnail,
|
|
arg.Icon,
|
|
)
|
|
var i ExamPrepUnitModule
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UnitID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.Thumbnail,
|
|
&i.Icon,
|
|
&i.SortOrder,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const ExamPrepDeleteUnitModule = `-- name: ExamPrepDeleteUnitModule :exec
|
|
DELETE FROM exam_prep.unit_modules
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) ExamPrepDeleteUnitModule(ctx context.Context, id int64) error {
|
|
_, err := q.db.Exec(ctx, ExamPrepDeleteUnitModule, id)
|
|
return err
|
|
}
|
|
|
|
const ExamPrepGetUnitModuleByID = `-- name: ExamPrepGetUnitModuleByID :one
|
|
SELECT id, unit_id, name, description, thumbnail, icon, sort_order, created_at, updated_at
|
|
FROM exam_prep.unit_modules
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) ExamPrepGetUnitModuleByID(ctx context.Context, id int64) (ExamPrepUnitModule, error) {
|
|
row := q.db.QueryRow(ctx, ExamPrepGetUnitModuleByID, id)
|
|
var i ExamPrepUnitModule
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UnitID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.Thumbnail,
|
|
&i.Icon,
|
|
&i.SortOrder,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const ExamPrepListUnitModuleIDsByUnit = `-- name: ExamPrepListUnitModuleIDsByUnit :many
|
|
SELECT
|
|
m.id
|
|
FROM exam_prep.unit_modules m
|
|
WHERE
|
|
m.unit_id = $1
|
|
ORDER BY
|
|
m.id
|
|
`
|
|
|
|
func (q *Queries) ExamPrepListUnitModuleIDsByUnit(ctx context.Context, unitID int64) ([]int64, error) {
|
|
rows, err := q.db.Query(ctx, ExamPrepListUnitModuleIDsByUnit, unitID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []int64
|
|
for rows.Next() {
|
|
var id int64
|
|
if err := rows.Scan(&id); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, id)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const ExamPrepListUnitModulesByUnit = `-- name: ExamPrepListUnitModulesByUnit :many
|
|
SELECT
|
|
COUNT(*) OVER () AS total_count,
|
|
m.id,
|
|
m.unit_id,
|
|
m.name,
|
|
m.description,
|
|
m.thumbnail,
|
|
m.icon,
|
|
m.sort_order,
|
|
m.created_at,
|
|
m.updated_at
|
|
FROM exam_prep.unit_modules m
|
|
WHERE
|
|
m.unit_id = $1
|
|
ORDER BY
|
|
m.sort_order ASC,
|
|
m.id ASC
|
|
LIMIT $2
|
|
OFFSET $3
|
|
`
|
|
|
|
type ExamPrepListUnitModulesByUnitParams struct {
|
|
UnitID int64 `json:"unit_id"`
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
type ExamPrepListUnitModulesByUnitRow struct {
|
|
TotalCount int64 `json:"total_count"`
|
|
ID int64 `json:"id"`
|
|
UnitID int64 `json:"unit_id"`
|
|
Name string `json:"name"`
|
|
Description pgtype.Text `json:"description"`
|
|
Thumbnail pgtype.Text `json:"thumbnail"`
|
|
Icon pgtype.Text `json:"icon"`
|
|
SortOrder int32 `json:"sort_order"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) ExamPrepListUnitModulesByUnit(ctx context.Context, arg ExamPrepListUnitModulesByUnitParams) ([]ExamPrepListUnitModulesByUnitRow, error) {
|
|
rows, err := q.db.Query(ctx, ExamPrepListUnitModulesByUnit, arg.UnitID, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ExamPrepListUnitModulesByUnitRow
|
|
for rows.Next() {
|
|
var i ExamPrepListUnitModulesByUnitRow
|
|
if err := rows.Scan(
|
|
&i.TotalCount,
|
|
&i.ID,
|
|
&i.UnitID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.Thumbnail,
|
|
&i.Icon,
|
|
&i.SortOrder,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const ExamPrepUpdateUnitModule = `-- name: ExamPrepUpdateUnitModule :one
|
|
UPDATE exam_prep.unit_modules
|
|
SET
|
|
name = coalesce($1::varchar, name),
|
|
description = coalesce($2::text, description),
|
|
thumbnail = coalesce($3::text, thumbnail),
|
|
icon = coalesce($4::text, icon),
|
|
sort_order = coalesce($5::int, sort_order),
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = $6
|
|
RETURNING
|
|
id, unit_id, name, description, thumbnail, icon, sort_order, created_at, updated_at
|
|
`
|
|
|
|
type ExamPrepUpdateUnitModuleParams struct {
|
|
Name pgtype.Text `json:"name"`
|
|
Description pgtype.Text `json:"description"`
|
|
Thumbnail pgtype.Text `json:"thumbnail"`
|
|
Icon pgtype.Text `json:"icon"`
|
|
SortOrder pgtype.Int4 `json:"sort_order"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) ExamPrepUpdateUnitModule(ctx context.Context, arg ExamPrepUpdateUnitModuleParams) (ExamPrepUnitModule, error) {
|
|
row := q.db.QueryRow(ctx, ExamPrepUpdateUnitModule,
|
|
arg.Name,
|
|
arg.Description,
|
|
arg.Thumbnail,
|
|
arg.Icon,
|
|
arg.SortOrder,
|
|
arg.ID,
|
|
)
|
|
var i ExamPrepUnitModule
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UnitID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.Thumbnail,
|
|
&i.Icon,
|
|
&i.SortOrder,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|