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

232 lines
5.6 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: exam_prep_units.sql
package dbgen
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const ExamPrepCreateUnit = `-- name: ExamPrepCreateUnit :one
INSERT INTO exam_prep.units (catalog_course_id, name, description, thumbnail, sort_order)
SELECT
$1,
$2,
$3,
$4,
coalesce((
SELECT
max(u.sort_order)
FROM exam_prep.units u
WHERE
u.catalog_course_id = $1), 0) + 1
RETURNING
id, catalog_course_id, name, description, thumbnail, sort_order, created_at, updated_at
`
type ExamPrepCreateUnitParams struct {
CatalogCourseID int64 `json:"catalog_course_id"`
Name string `json:"name"`
Description pgtype.Text `json:"description"`
Thumbnail pgtype.Text `json:"thumbnail"`
}
func (q *Queries) ExamPrepCreateUnit(ctx context.Context, arg ExamPrepCreateUnitParams) (ExamPrepUnit, error) {
row := q.db.QueryRow(ctx, ExamPrepCreateUnit,
arg.CatalogCourseID,
arg.Name,
arg.Description,
arg.Thumbnail,
)
var i ExamPrepUnit
err := row.Scan(
&i.ID,
&i.CatalogCourseID,
&i.Name,
&i.Description,
&i.Thumbnail,
&i.SortOrder,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const ExamPrepDeleteUnit = `-- name: ExamPrepDeleteUnit :exec
DELETE FROM exam_prep.units
WHERE id = $1
`
func (q *Queries) ExamPrepDeleteUnit(ctx context.Context, id int64) error {
_, err := q.db.Exec(ctx, ExamPrepDeleteUnit, id)
return err
}
const ExamPrepGetUnitByID = `-- name: ExamPrepGetUnitByID :one
SELECT id, catalog_course_id, name, description, thumbnail, sort_order, created_at, updated_at
FROM exam_prep.units
WHERE id = $1
`
func (q *Queries) ExamPrepGetUnitByID(ctx context.Context, id int64) (ExamPrepUnit, error) {
row := q.db.QueryRow(ctx, ExamPrepGetUnitByID, id)
var i ExamPrepUnit
err := row.Scan(
&i.ID,
&i.CatalogCourseID,
&i.Name,
&i.Description,
&i.Thumbnail,
&i.SortOrder,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const ExamPrepListUnitIDsByCatalogCourse = `-- name: ExamPrepListUnitIDsByCatalogCourse :many
SELECT
u.id
FROM exam_prep.units u
WHERE
u.catalog_course_id = $1
ORDER BY
u.id
`
func (q *Queries) ExamPrepListUnitIDsByCatalogCourse(ctx context.Context, catalogCourseID int64) ([]int64, error) {
rows, err := q.db.Query(ctx, ExamPrepListUnitIDsByCatalogCourse, catalogCourseID)
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 ExamPrepListUnitsByCatalogCourse = `-- name: ExamPrepListUnitsByCatalogCourse :many
SELECT
COUNT(*) OVER () AS total_count,
u.id,
u.catalog_course_id,
u.name,
u.description,
u.thumbnail,
u.sort_order,
u.created_at,
u.updated_at
FROM exam_prep.units u
WHERE
u.catalog_course_id = $1
ORDER BY
u.sort_order ASC,
u.id ASC
LIMIT $2
OFFSET $3
`
type ExamPrepListUnitsByCatalogCourseParams struct {
CatalogCourseID int64 `json:"catalog_course_id"`
Limit int32 `json:"limit"`
Offset int32 `json:"offset"`
}
type ExamPrepListUnitsByCatalogCourseRow struct {
TotalCount int64 `json:"total_count"`
ID int64 `json:"id"`
CatalogCourseID int64 `json:"catalog_course_id"`
Name string `json:"name"`
Description pgtype.Text `json:"description"`
Thumbnail pgtype.Text `json:"thumbnail"`
SortOrder int32 `json:"sort_order"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
}
func (q *Queries) ExamPrepListUnitsByCatalogCourse(ctx context.Context, arg ExamPrepListUnitsByCatalogCourseParams) ([]ExamPrepListUnitsByCatalogCourseRow, error) {
rows, err := q.db.Query(ctx, ExamPrepListUnitsByCatalogCourse, arg.CatalogCourseID, arg.Limit, arg.Offset)
if err != nil {
return nil, err
}
defer rows.Close()
var items []ExamPrepListUnitsByCatalogCourseRow
for rows.Next() {
var i ExamPrepListUnitsByCatalogCourseRow
if err := rows.Scan(
&i.TotalCount,
&i.ID,
&i.CatalogCourseID,
&i.Name,
&i.Description,
&i.Thumbnail,
&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 ExamPrepUpdateUnit = `-- name: ExamPrepUpdateUnit :one
UPDATE exam_prep.units
SET
name = coalesce($1::varchar, name),
description = coalesce($2::text, description),
thumbnail = coalesce($3::text, thumbnail),
sort_order = coalesce($4::int, sort_order),
updated_at = CURRENT_TIMESTAMP
WHERE id = $5
RETURNING
id, catalog_course_id, name, description, thumbnail, sort_order, created_at, updated_at
`
type ExamPrepUpdateUnitParams struct {
Name pgtype.Text `json:"name"`
Description pgtype.Text `json:"description"`
Thumbnail pgtype.Text `json:"thumbnail"`
SortOrder pgtype.Int4 `json:"sort_order"`
ID int64 `json:"id"`
}
func (q *Queries) ExamPrepUpdateUnit(ctx context.Context, arg ExamPrepUpdateUnitParams) (ExamPrepUnit, error) {
row := q.db.QueryRow(ctx, ExamPrepUpdateUnit,
arg.Name,
arg.Description,
arg.Thumbnail,
arg.SortOrder,
arg.ID,
)
var i ExamPrepUnit
err := row.Scan(
&i.ID,
&i.CatalogCourseID,
&i.Name,
&i.Description,
&i.Thumbnail,
&i.SortOrder,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}