364 lines
7.6 KiB
Go
364 lines
7.6 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,
|
|
|
|
is_published,
|
|
publish_date,
|
|
visibility,
|
|
|
|
instructor_id,
|
|
thumbnail,
|
|
is_active
|
|
)
|
|
VALUES (
|
|
$1, -- module_id
|
|
$2, -- title
|
|
$3, -- description
|
|
$4, -- video_url
|
|
$5, -- duration
|
|
$6, -- resolution
|
|
|
|
$7, -- is_published
|
|
$8, -- publish_date
|
|
$9, -- visibility
|
|
|
|
$10, -- instructor_id
|
|
$11, -- thumbnail
|
|
$12 -- is_active
|
|
)
|
|
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"`
|
|
IsPublished bool `json:"is_published"`
|
|
PublishDate pgtype.Timestamptz `json:"publish_date"`
|
|
Visibility pgtype.Text `json:"visibility"`
|
|
InstructorID pgtype.Text `json:"instructor_id"`
|
|
Thumbnail pgtype.Text `json:"thumbnail"`
|
|
IsActive bool `json:"is_active"`
|
|
}
|
|
|
|
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.IsPublished,
|
|
arg.PublishDate,
|
|
arg.Visibility,
|
|
arg.InstructorID,
|
|
arg.Thumbnail,
|
|
arg.IsActive,
|
|
)
|
|
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 DeactivateModuleVideo = `-- name: DeactivateModuleVideo :exec
|
|
UPDATE module_videos
|
|
SET is_active = FALSE
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeactivateModuleVideo(ctx context.Context, id int64) error {
|
|
_, err := q.db.Exec(ctx, DeactivateModuleVideo, id)
|
|
return err
|
|
}
|
|
|
|
const GetModuleVideoByID = `-- name: GetModuleVideoByID :one
|
|
SELECT
|
|
id,
|
|
module_id,
|
|
title,
|
|
description,
|
|
video_url,
|
|
duration,
|
|
resolution,
|
|
is_published,
|
|
publish_date,
|
|
visibility,
|
|
instructor_id,
|
|
thumbnail,
|
|
is_active
|
|
FROM module_videos
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetModuleVideoByID(ctx context.Context, id int64) (ModuleVideo, error) {
|
|
row := q.db.QueryRow(ctx, GetModuleVideoByID, id)
|
|
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 ListAllVideosByModule = `-- name: ListAllVideosByModule :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
|
|
ORDER BY id ASC
|
|
`
|
|
|
|
func (q *Queries) ListAllVideosByModule(ctx context.Context, moduleID int64) ([]ModuleVideo, error) {
|
|
rows, err := q.db.Query(ctx, ListAllVideosByModule, 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 ListPublishedVideosByModule = `-- name: ListPublishedVideosByModule :many
|
|
SELECT
|
|
id,
|
|
module_id,
|
|
title,
|
|
description,
|
|
video_url,
|
|
duration,
|
|
resolution,
|
|
publish_date,
|
|
visibility,
|
|
instructor_id,
|
|
thumbnail
|
|
FROM module_videos
|
|
WHERE module_id = $1
|
|
AND is_active = TRUE
|
|
AND is_published = TRUE
|
|
ORDER BY publish_date ASC, id ASC
|
|
`
|
|
|
|
type ListPublishedVideosByModuleRow struct {
|
|
ID int64 `json:"id"`
|
|
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"`
|
|
PublishDate pgtype.Timestamptz `json:"publish_date"`
|
|
Visibility pgtype.Text `json:"visibility"`
|
|
InstructorID pgtype.Text `json:"instructor_id"`
|
|
Thumbnail pgtype.Text `json:"thumbnail"`
|
|
}
|
|
|
|
func (q *Queries) ListPublishedVideosByModule(ctx context.Context, moduleID int64) ([]ListPublishedVideosByModuleRow, error) {
|
|
rows, err := q.db.Query(ctx, ListPublishedVideosByModule, moduleID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []ListPublishedVideosByModuleRow
|
|
for rows.Next() {
|
|
var i ListPublishedVideosByModuleRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.ModuleID,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.VideoUrl,
|
|
&i.Duration,
|
|
&i.Resolution,
|
|
&i.PublishDate,
|
|
&i.Visibility,
|
|
&i.InstructorID,
|
|
&i.Thumbnail,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const UpdateModuleVideo = `-- name: UpdateModuleVideo :one
|
|
UPDATE module_videos
|
|
SET
|
|
title = $2,
|
|
description = $3,
|
|
video_url = $4,
|
|
duration = $5,
|
|
resolution = $6,
|
|
|
|
is_published = $7,
|
|
publish_date = $8,
|
|
visibility = $9,
|
|
|
|
instructor_id = $10,
|
|
thumbnail = $11,
|
|
is_active = $12
|
|
WHERE id = $1
|
|
RETURNING
|
|
id,
|
|
module_id,
|
|
title,
|
|
description,
|
|
video_url,
|
|
duration,
|
|
resolution,
|
|
is_published,
|
|
publish_date,
|
|
visibility,
|
|
instructor_id,
|
|
thumbnail,
|
|
is_active
|
|
`
|
|
|
|
type UpdateModuleVideoParams struct {
|
|
ID int64 `json:"id"`
|
|
Title string `json:"title"`
|
|
Description pgtype.Text `json:"description"`
|
|
VideoUrl string `json:"video_url"`
|
|
Duration int32 `json:"duration"`
|
|
Resolution pgtype.Text `json:"resolution"`
|
|
IsPublished bool `json:"is_published"`
|
|
PublishDate pgtype.Timestamptz `json:"publish_date"`
|
|
Visibility pgtype.Text `json:"visibility"`
|
|
InstructorID pgtype.Text `json:"instructor_id"`
|
|
Thumbnail pgtype.Text `json:"thumbnail"`
|
|
IsActive bool `json:"is_active"`
|
|
}
|
|
|
|
func (q *Queries) UpdateModuleVideo(ctx context.Context, arg UpdateModuleVideoParams) (ModuleVideo, error) {
|
|
row := q.db.QueryRow(ctx, UpdateModuleVideo,
|
|
arg.ID,
|
|
arg.Title,
|
|
arg.Description,
|
|
arg.VideoUrl,
|
|
arg.Duration,
|
|
arg.Resolution,
|
|
arg.IsPublished,
|
|
arg.PublishDate,
|
|
arg.Visibility,
|
|
arg.InstructorID,
|
|
arg.Thumbnail,
|
|
arg.IsActive,
|
|
)
|
|
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
|
|
}
|