614 lines
15 KiB
Go
614 lines
15 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: lms_progress.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
const CountCoursesInProgram = `-- name: CountCoursesInProgram :one
|
|
SELECT
|
|
count(*)::int AS n
|
|
FROM
|
|
courses
|
|
WHERE
|
|
program_id = $1
|
|
`
|
|
|
|
func (q *Queries) CountCoursesInProgram(ctx context.Context, programID int64) (int32, error) {
|
|
row := q.db.QueryRow(ctx, CountCoursesInProgram, programID)
|
|
var n int32
|
|
err := row.Scan(&n)
|
|
return n, err
|
|
}
|
|
|
|
const CountLessonsInCourse = `-- name: CountLessonsInCourse :one
|
|
SELECT
|
|
count(*)::int AS n
|
|
FROM
|
|
lessons l
|
|
INNER JOIN modules m ON m.id = l.module_id
|
|
WHERE
|
|
m.course_id = $1
|
|
`
|
|
|
|
// Lesson-based progress within a course (all modules).
|
|
func (q *Queries) CountLessonsInCourse(ctx context.Context, courseID int64) (int32, error) {
|
|
row := q.db.QueryRow(ctx, CountLessonsInCourse, courseID)
|
|
var n int32
|
|
err := row.Scan(&n)
|
|
return n, err
|
|
}
|
|
|
|
const CountLessonsInModule = `-- name: CountLessonsInModule :one
|
|
SELECT
|
|
count(*)::int AS n
|
|
FROM
|
|
lessons
|
|
WHERE
|
|
module_id = $1
|
|
`
|
|
|
|
func (q *Queries) CountLessonsInModule(ctx context.Context, moduleID int64) (int32, error) {
|
|
row := q.db.QueryRow(ctx, CountLessonsInModule, moduleID)
|
|
var n int32
|
|
err := row.Scan(&n)
|
|
return n, err
|
|
}
|
|
|
|
const CountLessonsInProgram = `-- name: CountLessonsInProgram :one
|
|
SELECT
|
|
count(*)::int AS n
|
|
FROM
|
|
lessons l
|
|
INNER JOIN modules m ON m.id = l.module_id
|
|
INNER JOIN courses c ON c.id = m.course_id
|
|
WHERE
|
|
c.program_id = $1
|
|
`
|
|
|
|
// Lesson-based progress within a program (all courses).
|
|
func (q *Queries) CountLessonsInProgram(ctx context.Context, programID int64) (int32, error) {
|
|
row := q.db.QueryRow(ctx, CountLessonsInProgram, programID)
|
|
var n int32
|
|
err := row.Scan(&n)
|
|
return n, err
|
|
}
|
|
|
|
const CountModulesInCourse = `-- name: CountModulesInCourse :one
|
|
SELECT
|
|
count(*)::int AS n
|
|
FROM
|
|
modules
|
|
WHERE
|
|
course_id = $1
|
|
`
|
|
|
|
func (q *Queries) CountModulesInCourse(ctx context.Context, courseID int64) (int32, error) {
|
|
row := q.db.QueryRow(ctx, CountModulesInCourse, courseID)
|
|
var n int32
|
|
err := row.Scan(&n)
|
|
return n, err
|
|
}
|
|
|
|
const CountUserCompletedCoursesInProgram = `-- name: CountUserCompletedCoursesInProgram :one
|
|
SELECT
|
|
count(*)::int AS n
|
|
FROM
|
|
lms_user_course_progress ucp
|
|
INNER JOIN courses c ON c.id = ucp.course_id
|
|
WHERE
|
|
c.program_id = $1
|
|
AND ucp.user_id = $2
|
|
`
|
|
|
|
type CountUserCompletedCoursesInProgramParams struct {
|
|
ProgramID int64 `json:"program_id"`
|
|
UserID int64 `json:"user_id"`
|
|
}
|
|
|
|
func (q *Queries) CountUserCompletedCoursesInProgram(ctx context.Context, arg CountUserCompletedCoursesInProgramParams) (int32, error) {
|
|
row := q.db.QueryRow(ctx, CountUserCompletedCoursesInProgram, arg.ProgramID, arg.UserID)
|
|
var n int32
|
|
err := row.Scan(&n)
|
|
return n, err
|
|
}
|
|
|
|
const CountUserCompletedLessonsInCourse = `-- name: CountUserCompletedLessonsInCourse :one
|
|
SELECT
|
|
count(*)::int AS n
|
|
FROM
|
|
lms_user_lesson_progress ulp
|
|
INNER JOIN lessons l ON l.id = ulp.lesson_id
|
|
INNER JOIN modules m ON m.id = l.module_id
|
|
WHERE
|
|
m.course_id = $1
|
|
AND ulp.user_id = $2
|
|
`
|
|
|
|
type CountUserCompletedLessonsInCourseParams struct {
|
|
CourseID int64 `json:"course_id"`
|
|
UserID int64 `json:"user_id"`
|
|
}
|
|
|
|
func (q *Queries) CountUserCompletedLessonsInCourse(ctx context.Context, arg CountUserCompletedLessonsInCourseParams) (int32, error) {
|
|
row := q.db.QueryRow(ctx, CountUserCompletedLessonsInCourse, arg.CourseID, arg.UserID)
|
|
var n int32
|
|
err := row.Scan(&n)
|
|
return n, err
|
|
}
|
|
|
|
const CountUserCompletedLessonsInModule = `-- name: CountUserCompletedLessonsInModule :one
|
|
SELECT
|
|
count(*)::int AS n
|
|
FROM
|
|
lms_user_lesson_progress ulp
|
|
INNER JOIN lessons l ON l.id = ulp.lesson_id
|
|
WHERE
|
|
l.module_id = $1
|
|
AND ulp.user_id = $2
|
|
`
|
|
|
|
type CountUserCompletedLessonsInModuleParams struct {
|
|
ModuleID int64 `json:"module_id"`
|
|
UserID int64 `json:"user_id"`
|
|
}
|
|
|
|
func (q *Queries) CountUserCompletedLessonsInModule(ctx context.Context, arg CountUserCompletedLessonsInModuleParams) (int32, error) {
|
|
row := q.db.QueryRow(ctx, CountUserCompletedLessonsInModule, arg.ModuleID, arg.UserID)
|
|
var n int32
|
|
err := row.Scan(&n)
|
|
return n, err
|
|
}
|
|
|
|
const CountUserCompletedLessonsInProgram = `-- name: CountUserCompletedLessonsInProgram :one
|
|
SELECT
|
|
count(*)::int AS n
|
|
FROM
|
|
lms_user_lesson_progress ulp
|
|
INNER JOIN lessons l ON l.id = ulp.lesson_id
|
|
INNER JOIN modules m ON m.id = l.module_id
|
|
INNER JOIN courses c ON c.id = m.course_id
|
|
WHERE
|
|
c.program_id = $1
|
|
AND ulp.user_id = $2
|
|
`
|
|
|
|
type CountUserCompletedLessonsInProgramParams struct {
|
|
ProgramID int64 `json:"program_id"`
|
|
UserID int64 `json:"user_id"`
|
|
}
|
|
|
|
func (q *Queries) CountUserCompletedLessonsInProgram(ctx context.Context, arg CountUserCompletedLessonsInProgramParams) (int32, error) {
|
|
row := q.db.QueryRow(ctx, CountUserCompletedLessonsInProgram, arg.ProgramID, arg.UserID)
|
|
var n int32
|
|
err := row.Scan(&n)
|
|
return n, err
|
|
}
|
|
|
|
const CountUserCompletedModulesInCourse = `-- name: CountUserCompletedModulesInCourse :one
|
|
SELECT
|
|
count(*)::int AS n
|
|
FROM
|
|
lms_user_module_progress ump
|
|
INNER JOIN modules m ON m.id = ump.module_id
|
|
WHERE
|
|
m.course_id = $1
|
|
AND ump.user_id = $2
|
|
`
|
|
|
|
type CountUserCompletedModulesInCourseParams struct {
|
|
CourseID int64 `json:"course_id"`
|
|
UserID int64 `json:"user_id"`
|
|
}
|
|
|
|
func (q *Queries) CountUserCompletedModulesInCourse(ctx context.Context, arg CountUserCompletedModulesInCourseParams) (int32, error) {
|
|
row := q.db.QueryRow(ctx, CountUserCompletedModulesInCourse, arg.CourseID, arg.UserID)
|
|
var n int32
|
|
err := row.Scan(&n)
|
|
return n, err
|
|
}
|
|
|
|
const GetPreviousCourseInProgram = `-- name: GetPreviousCourseInProgram :one
|
|
SELECT
|
|
c2.id, c2.program_id, c2.name, c2.description, c2.thumbnail, c2.created_at, c2.updated_at, c2.sort_order
|
|
FROM
|
|
courses AS c1
|
|
INNER JOIN courses AS c2 ON c2.program_id = c1.program_id
|
|
AND c2.sort_order = c1.sort_order - 1
|
|
WHERE
|
|
c1.id = $1
|
|
`
|
|
|
|
func (q *Queries) GetPreviousCourseInProgram(ctx context.Context, id int64) (Course, error) {
|
|
row := q.db.QueryRow(ctx, GetPreviousCourseInProgram, id)
|
|
var i Course
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProgramID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.Thumbnail,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.SortOrder,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const GetPreviousLessonInModule = `-- name: GetPreviousLessonInModule :one
|
|
SELECT
|
|
l2.id, l2.module_id, l2.title, l2.video_url, l2.thumbnail, l2.description, l2.created_at, l2.updated_at, l2.sort_order
|
|
FROM
|
|
lessons AS l1
|
|
INNER JOIN lessons AS l2 ON l2.module_id = l1.module_id
|
|
AND l2.sort_order = l1.sort_order - 1
|
|
WHERE
|
|
l1.id = $1
|
|
`
|
|
|
|
func (q *Queries) GetPreviousLessonInModule(ctx context.Context, id int64) (Lesson, error) {
|
|
row := q.db.QueryRow(ctx, GetPreviousLessonInModule, id)
|
|
var i Lesson
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ModuleID,
|
|
&i.Title,
|
|
&i.VideoUrl,
|
|
&i.Thumbnail,
|
|
&i.Description,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.SortOrder,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const GetPreviousModuleInCourse = `-- name: GetPreviousModuleInCourse :one
|
|
SELECT
|
|
m2.id, m2.program_id, m2.course_id, m2.name, m2.description, m2.icon, m2.created_at, m2.updated_at, m2.sort_order
|
|
FROM
|
|
modules AS m1
|
|
INNER JOIN modules AS m2 ON m2.course_id = m1.course_id
|
|
AND m2.sort_order = m1.sort_order - 1
|
|
WHERE
|
|
m1.id = $1
|
|
`
|
|
|
|
func (q *Queries) GetPreviousModuleInCourse(ctx context.Context, id int64) (Module, error) {
|
|
row := q.db.QueryRow(ctx, GetPreviousModuleInCourse, id)
|
|
var i Module
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProgramID,
|
|
&i.CourseID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.Icon,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.SortOrder,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const GetPreviousProgram = `-- name: GetPreviousProgram :one
|
|
SELECT
|
|
p2.id, p2.name, p2.description, p2.thumbnail, p2.created_at, p2.updated_at, p2.sort_order
|
|
FROM
|
|
programs AS p1
|
|
INNER JOIN programs AS p2 ON p2.sort_order = p1.sort_order - 1
|
|
WHERE
|
|
p1.id = $1
|
|
`
|
|
|
|
func (q *Queries) GetPreviousProgram(ctx context.Context, id int64) (Program, error) {
|
|
row := q.db.QueryRow(ctx, GetPreviousProgram, id)
|
|
var i Program
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.Thumbnail,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.SortOrder,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const InsertUserCourseProgress = `-- name: InsertUserCourseProgress :exec
|
|
INSERT INTO lms_user_course_progress (user_id, course_id)
|
|
VALUES ($1, $2)
|
|
ON CONFLICT (user_id, course_id)
|
|
DO NOTHING
|
|
`
|
|
|
|
type InsertUserCourseProgressParams struct {
|
|
UserID int64 `json:"user_id"`
|
|
CourseID int64 `json:"course_id"`
|
|
}
|
|
|
|
func (q *Queries) InsertUserCourseProgress(ctx context.Context, arg InsertUserCourseProgressParams) error {
|
|
_, err := q.db.Exec(ctx, InsertUserCourseProgress, arg.UserID, arg.CourseID)
|
|
return err
|
|
}
|
|
|
|
const InsertUserLessonProgress = `-- name: InsertUserLessonProgress :exec
|
|
INSERT INTO lms_user_lesson_progress (user_id, lesson_id)
|
|
VALUES ($1, $2)
|
|
ON CONFLICT (user_id, lesson_id)
|
|
DO NOTHING
|
|
`
|
|
|
|
type InsertUserLessonProgressParams struct {
|
|
UserID int64 `json:"user_id"`
|
|
LessonID int64 `json:"lesson_id"`
|
|
}
|
|
|
|
func (q *Queries) InsertUserLessonProgress(ctx context.Context, arg InsertUserLessonProgressParams) error {
|
|
_, err := q.db.Exec(ctx, InsertUserLessonProgress, arg.UserID, arg.LessonID)
|
|
return err
|
|
}
|
|
|
|
const InsertUserModuleProgress = `-- name: InsertUserModuleProgress :exec
|
|
INSERT INTO lms_user_module_progress (user_id, module_id)
|
|
VALUES ($1, $2)
|
|
ON CONFLICT (user_id, module_id)
|
|
DO NOTHING
|
|
`
|
|
|
|
type InsertUserModuleProgressParams struct {
|
|
UserID int64 `json:"user_id"`
|
|
ModuleID int64 `json:"module_id"`
|
|
}
|
|
|
|
func (q *Queries) InsertUserModuleProgress(ctx context.Context, arg InsertUserModuleProgressParams) error {
|
|
_, err := q.db.Exec(ctx, InsertUserModuleProgress, arg.UserID, arg.ModuleID)
|
|
return err
|
|
}
|
|
|
|
const InsertUserProgramProgress = `-- name: InsertUserProgramProgress :exec
|
|
INSERT INTO lms_user_program_progress (user_id, program_id)
|
|
VALUES ($1, $2)
|
|
ON CONFLICT (user_id, program_id)
|
|
DO NOTHING
|
|
`
|
|
|
|
type InsertUserProgramProgressParams struct {
|
|
UserID int64 `json:"user_id"`
|
|
ProgramID int64 `json:"program_id"`
|
|
}
|
|
|
|
func (q *Queries) InsertUserProgramProgress(ctx context.Context, arg InsertUserProgramProgressParams) error {
|
|
_, err := q.db.Exec(ctx, InsertUserProgramProgress, arg.UserID, arg.ProgramID)
|
|
return err
|
|
}
|
|
|
|
const ListLMSCompletedCourseIDsByUser = `-- name: ListLMSCompletedCourseIDsByUser :many
|
|
SELECT
|
|
ucp.course_id
|
|
FROM
|
|
lms_user_course_progress AS ucp
|
|
WHERE
|
|
ucp.user_id = $1
|
|
ORDER BY
|
|
ucp.completed_at ASC,
|
|
ucp.course_id ASC
|
|
`
|
|
|
|
func (q *Queries) ListLMSCompletedCourseIDsByUser(ctx context.Context, userID int64) ([]int64, error) {
|
|
rows, err := q.db.Query(ctx, ListLMSCompletedCourseIDsByUser, userID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []int64
|
|
for rows.Next() {
|
|
var course_id int64
|
|
if err := rows.Scan(&course_id); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, course_id)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const ListLMSCompletedLessonIDsByUser = `-- name: ListLMSCompletedLessonIDsByUser :many
|
|
SELECT
|
|
ulp.lesson_id
|
|
FROM
|
|
lms_user_lesson_progress AS ulp
|
|
WHERE
|
|
ulp.user_id = $1
|
|
ORDER BY
|
|
ulp.completed_at ASC,
|
|
ulp.lesson_id ASC
|
|
`
|
|
|
|
func (q *Queries) ListLMSCompletedLessonIDsByUser(ctx context.Context, userID int64) ([]int64, error) {
|
|
rows, err := q.db.Query(ctx, ListLMSCompletedLessonIDsByUser, userID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []int64
|
|
for rows.Next() {
|
|
var lesson_id int64
|
|
if err := rows.Scan(&lesson_id); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, lesson_id)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const ListLMSCompletedModuleIDsByUser = `-- name: ListLMSCompletedModuleIDsByUser :many
|
|
SELECT
|
|
ump.module_id
|
|
FROM
|
|
lms_user_module_progress AS ump
|
|
WHERE
|
|
ump.user_id = $1
|
|
ORDER BY
|
|
ump.completed_at ASC,
|
|
ump.module_id ASC
|
|
`
|
|
|
|
func (q *Queries) ListLMSCompletedModuleIDsByUser(ctx context.Context, userID int64) ([]int64, error) {
|
|
rows, err := q.db.Query(ctx, ListLMSCompletedModuleIDsByUser, userID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []int64
|
|
for rows.Next() {
|
|
var module_id int64
|
|
if err := rows.Scan(&module_id); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, module_id)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const ListLMSCompletedProgramIDsByUser = `-- name: ListLMSCompletedProgramIDsByUser :many
|
|
SELECT
|
|
upp.program_id
|
|
FROM
|
|
lms_user_program_progress AS upp
|
|
WHERE
|
|
upp.user_id = $1
|
|
ORDER BY
|
|
upp.completed_at ASC,
|
|
upp.program_id ASC
|
|
`
|
|
|
|
func (q *Queries) ListLMSCompletedProgramIDsByUser(ctx context.Context, userID int64) ([]int64, error) {
|
|
rows, err := q.db.Query(ctx, ListLMSCompletedProgramIDsByUser, userID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []int64
|
|
for rows.Next() {
|
|
var program_id int64
|
|
if err := rows.Scan(&program_id); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, program_id)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const UserHasCourseProgress = `-- name: UserHasCourseProgress :one
|
|
SELECT
|
|
EXISTS (
|
|
SELECT
|
|
1
|
|
FROM
|
|
lms_user_course_progress
|
|
WHERE
|
|
user_id = $1
|
|
AND course_id = $2) AS v
|
|
`
|
|
|
|
type UserHasCourseProgressParams struct {
|
|
UserID int64 `json:"user_id"`
|
|
CourseID int64 `json:"course_id"`
|
|
}
|
|
|
|
func (q *Queries) UserHasCourseProgress(ctx context.Context, arg UserHasCourseProgressParams) (bool, error) {
|
|
row := q.db.QueryRow(ctx, UserHasCourseProgress, arg.UserID, arg.CourseID)
|
|
var v bool
|
|
err := row.Scan(&v)
|
|
return v, err
|
|
}
|
|
|
|
const UserHasLessonProgress = `-- name: UserHasLessonProgress :one
|
|
SELECT
|
|
EXISTS (
|
|
SELECT
|
|
1
|
|
FROM
|
|
lms_user_lesson_progress
|
|
WHERE
|
|
user_id = $1
|
|
AND lesson_id = $2) AS v
|
|
`
|
|
|
|
type UserHasLessonProgressParams struct {
|
|
UserID int64 `json:"user_id"`
|
|
LessonID int64 `json:"lesson_id"`
|
|
}
|
|
|
|
func (q *Queries) UserHasLessonProgress(ctx context.Context, arg UserHasLessonProgressParams) (bool, error) {
|
|
row := q.db.QueryRow(ctx, UserHasLessonProgress, arg.UserID, arg.LessonID)
|
|
var v bool
|
|
err := row.Scan(&v)
|
|
return v, err
|
|
}
|
|
|
|
const UserHasModuleProgress = `-- name: UserHasModuleProgress :one
|
|
SELECT
|
|
EXISTS (
|
|
SELECT
|
|
1
|
|
FROM
|
|
lms_user_module_progress
|
|
WHERE
|
|
user_id = $1
|
|
AND module_id = $2) AS v
|
|
`
|
|
|
|
type UserHasModuleProgressParams struct {
|
|
UserID int64 `json:"user_id"`
|
|
ModuleID int64 `json:"module_id"`
|
|
}
|
|
|
|
func (q *Queries) UserHasModuleProgress(ctx context.Context, arg UserHasModuleProgressParams) (bool, error) {
|
|
row := q.db.QueryRow(ctx, UserHasModuleProgress, arg.UserID, arg.ModuleID)
|
|
var v bool
|
|
err := row.Scan(&v)
|
|
return v, err
|
|
}
|
|
|
|
const UserHasProgramProgress = `-- name: UserHasProgramProgress :one
|
|
SELECT
|
|
EXISTS (
|
|
SELECT
|
|
1
|
|
FROM
|
|
lms_user_program_progress
|
|
WHERE
|
|
user_id = $1
|
|
AND program_id = $2) AS v
|
|
`
|
|
|
|
type UserHasProgramProgressParams struct {
|
|
UserID int64 `json:"user_id"`
|
|
ProgramID int64 `json:"program_id"`
|
|
}
|
|
|
|
func (q *Queries) UserHasProgramProgress(ctx context.Context, arg UserHasProgramProgressParams) (bool, error) {
|
|
row := q.db.QueryRow(ctx, UserHasProgramProgress, arg.UserID, arg.ProgramID)
|
|
var v bool
|
|
err := row.Scan(&v)
|
|
return v, err
|
|
}
|