186 lines
4.4 KiB
Go
186 lines
4.4 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: module_videos.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const CreateModuleVideo = `-- name: CreateModuleVideo :one
|
|
INSERT INTO module_videos (
|
|
module_id,
|
|
title,
|
|
description,
|
|
video_url,
|
|
duration,
|
|
resolution,
|
|
instructor_id,
|
|
thumbnail,
|
|
visibility,
|
|
is_active
|
|
)
|
|
VALUES (
|
|
$1, $2, $3, $4, $5, $6,
|
|
$7, $8, $9,
|
|
COALESCE($10, true)
|
|
)
|
|
RETURNING id, module_id, title, description, video_url, duration, resolution, is_published, publish_date, visibility, instructor_id, thumbnail, is_active
|
|
`
|
|
|
|
type CreateModuleVideoParams struct {
|
|
ModuleID int64 `json:"module_id"`
|
|
Title string `json:"title"`
|
|
Description pgtype.Text `json:"description"`
|
|
VideoUrl string `json:"video_url"`
|
|
Duration int32 `json:"duration"`
|
|
Resolution pgtype.Text `json:"resolution"`
|
|
InstructorID pgtype.Text `json:"instructor_id"`
|
|
Thumbnail pgtype.Text `json:"thumbnail"`
|
|
Visibility pgtype.Text `json:"visibility"`
|
|
Column10 interface{} `json:"column_10"`
|
|
}
|
|
|
|
func (q *Queries) CreateModuleVideo(ctx context.Context, arg CreateModuleVideoParams) (ModuleVideo, error) {
|
|
row := q.db.QueryRow(ctx, CreateModuleVideo,
|
|
arg.ModuleID,
|
|
arg.Title,
|
|
arg.Description,
|
|
arg.VideoUrl,
|
|
arg.Duration,
|
|
arg.Resolution,
|
|
arg.InstructorID,
|
|
arg.Thumbnail,
|
|
arg.Visibility,
|
|
arg.Column10,
|
|
)
|
|
var i ModuleVideo
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ModuleID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.VideoUrl,
|
|
&i.Duration,
|
|
&i.Resolution,
|
|
&i.IsPublished,
|
|
&i.PublishDate,
|
|
&i.Visibility,
|
|
&i.InstructorID,
|
|
&i.Thumbnail,
|
|
&i.IsActive,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const DeleteModuleVideo = `-- name: DeleteModuleVideo :exec
|
|
DELETE FROM module_videos
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteModuleVideo(ctx context.Context, id int64) error {
|
|
_, err := q.db.Exec(ctx, DeleteModuleVideo, id)
|
|
return err
|
|
}
|
|
|
|
const GetPublishedVideosByModule = `-- name: GetPublishedVideosByModule :many
|
|
SELECT id, module_id, title, description, video_url, duration, resolution, is_published, publish_date, visibility, instructor_id, thumbnail, is_active
|
|
FROM module_videos
|
|
WHERE module_id = $1
|
|
AND is_published = true
|
|
AND is_active = true
|
|
ORDER BY publish_date ASC
|
|
`
|
|
|
|
func (q *Queries) GetPublishedVideosByModule(ctx context.Context, moduleID int64) ([]ModuleVideo, error) {
|
|
rows, err := q.db.Query(ctx, GetPublishedVideosByModule, moduleID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ModuleVideo
|
|
for rows.Next() {
|
|
var i ModuleVideo
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.ModuleID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.VideoUrl,
|
|
&i.Duration,
|
|
&i.Resolution,
|
|
&i.IsPublished,
|
|
&i.PublishDate,
|
|
&i.Visibility,
|
|
&i.InstructorID,
|
|
&i.Thumbnail,
|
|
&i.IsActive,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const PublishModuleVideo = `-- name: PublishModuleVideo :exec
|
|
UPDATE module_videos
|
|
SET
|
|
is_published = true,
|
|
publish_date = CURRENT_TIMESTAMP
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) PublishModuleVideo(ctx context.Context, id int64) error {
|
|
_, err := q.db.Exec(ctx, PublishModuleVideo, id)
|
|
return err
|
|
}
|
|
|
|
const UpdateModuleVideo = `-- name: UpdateModuleVideo :exec
|
|
UPDATE module_videos
|
|
SET
|
|
title = COALESCE($1, title),
|
|
description = COALESCE($2, description),
|
|
video_url = COALESCE($3, video_url),
|
|
duration = COALESCE($4, duration),
|
|
resolution = COALESCE($5, resolution),
|
|
visibility = COALESCE($6, visibility),
|
|
thumbnail = COALESCE($7, thumbnail),
|
|
is_active = COALESCE($8, is_active)
|
|
WHERE id = $9
|
|
`
|
|
|
|
type UpdateModuleVideoParams struct {
|
|
Title string `json:"title"`
|
|
Description pgtype.Text `json:"description"`
|
|
VideoUrl string `json:"video_url"`
|
|
Duration int32 `json:"duration"`
|
|
Resolution pgtype.Text `json:"resolution"`
|
|
Visibility pgtype.Text `json:"visibility"`
|
|
Thumbnail pgtype.Text `json:"thumbnail"`
|
|
IsActive bool `json:"is_active"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateModuleVideo(ctx context.Context, arg UpdateModuleVideoParams) error {
|
|
_, err := q.db.Exec(ctx, UpdateModuleVideo,
|
|
arg.Title,
|
|
arg.Description,
|
|
arg.VideoUrl,
|
|
arg.Duration,
|
|
arg.Resolution,
|
|
arg.Visibility,
|
|
arg.Thumbnail,
|
|
arg.IsActive,
|
|
arg.ID,
|
|
)
|
|
return err
|
|
}
|