// 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, is_active ) VALUES ($1, $2, $3, COALESCE($4, true)) RETURNING id, category_id, title, description, is_active ` type CreateCourseParams struct { CategoryID int64 `json:"category_id"` Title string `json:"title"` Description pgtype.Text `json:"description"` Column4 interface{} `json:"column_4"` } func (q *Queries) CreateCourse(ctx context.Context, arg CreateCourseParams) (Course, error) { row := q.db.QueryRow(ctx, CreateCourse, arg.CategoryID, arg.Title, arg.Description, arg.Column4, ) var i Course err := row.Scan( &i.ID, &i.CategoryID, &i.Title, &i.Description, &i.IsActive, ) 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 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, ) return i, err } const GetCoursesByCategory = `-- name: GetCoursesByCategory :many SELECT COUNT(*) OVER () AS total_count, id, category_id, title, description, 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"` 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.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), is_active = COALESCE($3, is_active) WHERE id = $4 ` type UpdateCourseParams struct { Title string `json:"title"` Description pgtype.Text `json:"description"` 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.IsActive, arg.ID, ) return err }