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

188 lines
4.3 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: lms_lessons.sql
package dbgen
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const CreateLesson = `-- name: CreateLesson :one
INSERT INTO lessons (module_id, title, video_url, thumbnail, description)
VALUES ($1, $2, $3, $4, $5)
RETURNING id, module_id, title, video_url, thumbnail, description, created_at, updated_at
`
type CreateLessonParams struct {
ModuleID int64 `json:"module_id"`
Title string `json:"title"`
VideoUrl pgtype.Text `json:"video_url"`
Thumbnail pgtype.Text `json:"thumbnail"`
Description pgtype.Text `json:"description"`
}
func (q *Queries) CreateLesson(ctx context.Context, arg CreateLessonParams) (Lesson, error) {
row := q.db.QueryRow(ctx, CreateLesson,
arg.ModuleID,
arg.Title,
arg.VideoUrl,
arg.Thumbnail,
arg.Description,
)
var i Lesson
err := row.Scan(
&i.ID,
&i.ModuleID,
&i.Title,
&i.VideoUrl,
&i.Thumbnail,
&i.Description,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const DeleteLesson = `-- name: DeleteLesson :exec
DELETE FROM lessons
WHERE id = $1
`
func (q *Queries) DeleteLesson(ctx context.Context, id int64) error {
_, err := q.db.Exec(ctx, DeleteLesson, id)
return err
}
const GetLessonByID = `-- name: GetLessonByID :one
SELECT id, module_id, title, video_url, thumbnail, description, created_at, updated_at
FROM lessons
WHERE id = $1
`
func (q *Queries) GetLessonByID(ctx context.Context, id int64) (Lesson, error) {
row := q.db.QueryRow(ctx, GetLessonByID, id)
var i Lesson
err := row.Scan(
&i.ID,
&i.ModuleID,
&i.Title,
&i.VideoUrl,
&i.Thumbnail,
&i.Description,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const ListLessonsByModuleID = `-- name: ListLessonsByModuleID :many
SELECT
COUNT(*) OVER () AS total_count,
l.id,
l.module_id,
l.title,
l.video_url,
l.thumbnail,
l.description,
l.created_at,
l.updated_at
FROM lessons l
WHERE l.module_id = $1
ORDER BY l.created_at DESC
LIMIT $2 OFFSET $3
`
type ListLessonsByModuleIDParams struct {
ModuleID int64 `json:"module_id"`
Limit int32 `json:"limit"`
Offset int32 `json:"offset"`
}
type ListLessonsByModuleIDRow struct {
TotalCount int64 `json:"total_count"`
ID int64 `json:"id"`
ModuleID int64 `json:"module_id"`
Title string `json:"title"`
VideoUrl pgtype.Text `json:"video_url"`
Thumbnail pgtype.Text `json:"thumbnail"`
Description pgtype.Text `json:"description"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
}
func (q *Queries) ListLessonsByModuleID(ctx context.Context, arg ListLessonsByModuleIDParams) ([]ListLessonsByModuleIDRow, error) {
rows, err := q.db.Query(ctx, ListLessonsByModuleID, arg.ModuleID, arg.Limit, arg.Offset)
if err != nil {
return nil, err
}
defer rows.Close()
var items []ListLessonsByModuleIDRow
for rows.Next() {
var i ListLessonsByModuleIDRow
if err := rows.Scan(
&i.TotalCount,
&i.ID,
&i.ModuleID,
&i.Title,
&i.VideoUrl,
&i.Thumbnail,
&i.Description,
&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 UpdateLesson = `-- name: UpdateLesson :one
UPDATE lessons
SET
title = COALESCE($1::varchar, title),
video_url = COALESCE($2::text, video_url),
thumbnail = COALESCE($3::text, thumbnail),
description = COALESCE($4::text, description),
updated_at = CURRENT_TIMESTAMP
WHERE id = $5
RETURNING id, module_id, title, video_url, thumbnail, description, created_at, updated_at
`
type UpdateLessonParams struct {
Title pgtype.Text `json:"title"`
VideoUrl pgtype.Text `json:"video_url"`
Thumbnail pgtype.Text `json:"thumbnail"`
Description pgtype.Text `json:"description"`
ID int64 `json:"id"`
}
func (q *Queries) UpdateLesson(ctx context.Context, arg UpdateLessonParams) (Lesson, error) {
row := q.db.QueryRow(ctx, UpdateLesson,
arg.Title,
arg.VideoUrl,
arg.Thumbnail,
arg.Description,
arg.ID,
)
var i Lesson
err := row.Scan(
&i.ID,
&i.ModuleID,
&i.Title,
&i.VideoUrl,
&i.Thumbnail,
&i.Description,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}