188 lines
3.4 KiB
Go
188 lines
3.4 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: level_modules.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const CreateModule = `-- name: CreateModule :one
|
|
INSERT INTO modules (
|
|
level_id,
|
|
title,
|
|
content,
|
|
display_order,
|
|
is_active
|
|
)
|
|
VALUES (
|
|
$1, -- level_id
|
|
$2, -- title
|
|
$3, -- content
|
|
$4, -- display_order
|
|
$5 -- is_active
|
|
)
|
|
RETURNING
|
|
id,
|
|
level_id,
|
|
title,
|
|
content,
|
|
display_order,
|
|
is_active
|
|
`
|
|
|
|
type CreateModuleParams struct {
|
|
LevelID int64 `json:"level_id"`
|
|
Title string `json:"title"`
|
|
Content pgtype.Text `json:"content"`
|
|
DisplayOrder int32 `json:"display_order"`
|
|
IsActive bool `json:"is_active"`
|
|
}
|
|
|
|
func (q *Queries) CreateModule(ctx context.Context, arg CreateModuleParams) (Module, error) {
|
|
row := q.db.QueryRow(ctx, CreateModule,
|
|
arg.LevelID,
|
|
arg.Title,
|
|
arg.Content,
|
|
arg.DisplayOrder,
|
|
arg.IsActive,
|
|
)
|
|
var i Module
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.LevelID,
|
|
&i.Title,
|
|
&i.Content,
|
|
&i.DisplayOrder,
|
|
&i.IsActive,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const DeactivateModule = `-- name: DeactivateModule :exec
|
|
UPDATE modules
|
|
SET is_active = FALSE
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeactivateModule(ctx context.Context, id int64) error {
|
|
_, err := q.db.Exec(ctx, DeactivateModule, id)
|
|
return err
|
|
}
|
|
|
|
const GetModuleByID = `-- name: GetModuleByID :one
|
|
SELECT
|
|
id,
|
|
level_id,
|
|
title,
|
|
content,
|
|
display_order,
|
|
is_active
|
|
FROM modules
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetModuleByID(ctx context.Context, id int64) (Module, error) {
|
|
row := q.db.QueryRow(ctx, GetModuleByID, id)
|
|
var i Module
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.LevelID,
|
|
&i.Title,
|
|
&i.Content,
|
|
&i.DisplayOrder,
|
|
&i.IsActive,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const ListModulesByLevel = `-- name: ListModulesByLevel :many
|
|
SELECT
|
|
id,
|
|
level_id,
|
|
title,
|
|
content,
|
|
display_order,
|
|
is_active
|
|
FROM modules
|
|
WHERE level_id = $1
|
|
AND is_active = TRUE
|
|
ORDER BY display_order ASC, id ASC
|
|
`
|
|
|
|
func (q *Queries) ListModulesByLevel(ctx context.Context, levelID int64) ([]Module, error) {
|
|
rows, err := q.db.Query(ctx, ListModulesByLevel, levelID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Module
|
|
for rows.Next() {
|
|
var i Module
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.LevelID,
|
|
&i.Title,
|
|
&i.Content,
|
|
&i.DisplayOrder,
|
|
&i.IsActive,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const UpdateModule = `-- name: UpdateModule :one
|
|
UPDATE modules
|
|
SET
|
|
title = $2,
|
|
content = $3,
|
|
display_order = $4,
|
|
is_active = $5
|
|
WHERE id = $1
|
|
RETURNING
|
|
id,
|
|
level_id,
|
|
title,
|
|
content,
|
|
display_order,
|
|
is_active
|
|
`
|
|
|
|
type UpdateModuleParams struct {
|
|
ID int64 `json:"id"`
|
|
Title string `json:"title"`
|
|
Content pgtype.Text `json:"content"`
|
|
DisplayOrder int32 `json:"display_order"`
|
|
IsActive bool `json:"is_active"`
|
|
}
|
|
|
|
func (q *Queries) UpdateModule(ctx context.Context, arg UpdateModuleParams) (Module, error) {
|
|
row := q.db.QueryRow(ctx, UpdateModule,
|
|
arg.ID,
|
|
arg.Title,
|
|
arg.Content,
|
|
arg.DisplayOrder,
|
|
arg.IsActive,
|
|
)
|
|
var i Module
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.LevelID,
|
|
&i.Title,
|
|
&i.Content,
|
|
&i.DisplayOrder,
|
|
&i.IsActive,
|
|
)
|
|
return i, err
|
|
}
|