// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.30.0 // source: courses.sql package dbgen import ( "context" "github.com/jackc/pgx/v5/pgtype" ) const CreateCourse = `-- name: CreateCourse :one INSERT INTO courses ( category_id, title, description, thumbnail, intro_video_url, is_active ) VALUES ($1, $2, $3, $4, $5, COALESCE($6, true)) RETURNING id, category_id, title, description, is_active, thumbnail, intro_video_url ` type CreateCourseParams struct { CategoryID int64 `json:"category_id"` Title string `json:"title"` Description pgtype.Text `json:"description"` Thumbnail pgtype.Text `json:"thumbnail"` IntroVideoUrl pgtype.Text `json:"intro_video_url"` Column6 interface{} `json:"column_6"` } func (q *Queries) CreateCourse(ctx context.Context, arg CreateCourseParams) (Course, error) { row := q.db.QueryRow(ctx, CreateCourse, arg.CategoryID, arg.Title, arg.Description, arg.Thumbnail, arg.IntroVideoUrl, arg.Column6, ) var i Course err := row.Scan( &i.ID, &i.CategoryID, &i.Title, &i.Description, &i.IsActive, &i.Thumbnail, &i.IntroVideoUrl, ) return i, err } const DeleteCourse = `-- name: DeleteCourse :exec DELETE FROM courses WHERE id = $1 ` func (q *Queries) DeleteCourse(ctx context.Context, id int64) error { _, err := q.db.Exec(ctx, DeleteCourse, id) return err } const GetCourseByID = `-- name: GetCourseByID :one SELECT id, category_id, title, description, is_active, thumbnail, intro_video_url FROM courses WHERE id = $1 ` func (q *Queries) GetCourseByID(ctx context.Context, id int64) (Course, error) { row := q.db.QueryRow(ctx, GetCourseByID, id) var i Course err := row.Scan( &i.ID, &i.CategoryID, &i.Title, &i.Description, &i.IsActive, &i.Thumbnail, &i.IntroVideoUrl, ) return i, err } const GetCoursesByCategory = `-- name: GetCoursesByCategory :many SELECT COUNT(*) OVER () AS total_count, id, category_id, title, description, thumbnail, intro_video_url, is_active FROM courses WHERE category_id = $1 ORDER BY id DESC LIMIT $3::INT OFFSET $2::INT ` type GetCoursesByCategoryParams struct { CategoryID int64 `json:"category_id"` Offset pgtype.Int4 `json:"offset"` Limit pgtype.Int4 `json:"limit"` } type GetCoursesByCategoryRow struct { TotalCount int64 `json:"total_count"` ID int64 `json:"id"` CategoryID int64 `json:"category_id"` Title string `json:"title"` Description pgtype.Text `json:"description"` Thumbnail pgtype.Text `json:"thumbnail"` IntroVideoUrl pgtype.Text `json:"intro_video_url"` IsActive bool `json:"is_active"` } func (q *Queries) GetCoursesByCategory(ctx context.Context, arg GetCoursesByCategoryParams) ([]GetCoursesByCategoryRow, error) { rows, err := q.db.Query(ctx, GetCoursesByCategory, arg.CategoryID, arg.Offset, arg.Limit) if err != nil { return nil, err } defer rows.Close() var items []GetCoursesByCategoryRow for rows.Next() { var i GetCoursesByCategoryRow if err := rows.Scan( &i.TotalCount, &i.ID, &i.CategoryID, &i.Title, &i.Description, &i.Thumbnail, &i.IntroVideoUrl, &i.IsActive, ); err != nil { return nil, err } items = append(items, i) } if err := rows.Err(); err != nil { return nil, err } return items, nil } const UpdateCourse = `-- name: UpdateCourse :exec UPDATE courses SET title = COALESCE($1, title), description = COALESCE($2, description), thumbnail = COALESCE($3, thumbnail), intro_video_url = COALESCE($4, intro_video_url), is_active = COALESCE($5, is_active) WHERE id = $6 ` type UpdateCourseParams struct { Title string `json:"title"` Description pgtype.Text `json:"description"` Thumbnail pgtype.Text `json:"thumbnail"` IntroVideoUrl pgtype.Text `json:"intro_video_url"` IsActive bool `json:"is_active"` ID int64 `json:"id"` } func (q *Queries) UpdateCourse(ctx context.Context, arg UpdateCourseParams) error { _, err := q.db.Exec(ctx, UpdateCourse, arg.Title, arg.Description, arg.Thumbnail, arg.IntroVideoUrl, arg.IsActive, arg.ID, ) return err }