Yimaru-BackEnd/gen/db/level_modules.sql.go

144 lines
3.0 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, $2, $3, COALESCE($4, 0), COALESCE($5, true))
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"`
Column4 interface{} `json:"column_4"`
Column5 interface{} `json:"column_5"`
}
func (q *Queries) CreateModule(ctx context.Context, arg CreateModuleParams) (Module, error) {
row := q.db.QueryRow(ctx, CreateModule,
arg.LevelID,
arg.Title,
arg.Content,
arg.Column4,
arg.Column5,
)
var i Module
err := row.Scan(
&i.ID,
&i.LevelID,
&i.Title,
&i.Content,
&i.DisplayOrder,
&i.IsActive,
)
return i, err
}
const DeleteModule = `-- name: DeleteModule :exec
DELETE FROM modules
WHERE id = $1
`
func (q *Queries) DeleteModule(ctx context.Context, id int64) error {
_, err := q.db.Exec(ctx, DeleteModule, id)
return err
}
const GetModulesByLevel = `-- name: GetModulesByLevel :many
SELECT
COUNT(*) OVER () AS total_count,
id,
level_id,
title,
content,
display_order,
is_active
FROM modules
WHERE level_id = $1
ORDER BY display_order ASC
`
type GetModulesByLevelRow struct {
TotalCount int64 `json:"total_count"`
ID int64 `json:"id"`
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) GetModulesByLevel(ctx context.Context, levelID int64) ([]GetModulesByLevelRow, error) {
rows, err := q.db.Query(ctx, GetModulesByLevel, levelID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetModulesByLevelRow
for rows.Next() {
var i GetModulesByLevelRow
if err := rows.Scan(
&i.TotalCount,
&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 :exec
UPDATE modules
SET
title = COALESCE($1, title),
content = COALESCE($2, content),
display_order = COALESCE($3, display_order),
is_active = COALESCE($4, is_active)
WHERE id = $5
`
type UpdateModuleParams struct {
Title string `json:"title"`
Content pgtype.Text `json:"content"`
DisplayOrder int32 `json:"display_order"`
IsActive bool `json:"is_active"`
ID int64 `json:"id"`
}
func (q *Queries) UpdateModule(ctx context.Context, arg UpdateModuleParams) error {
_, err := q.db.Exec(ctx, UpdateModule,
arg.Title,
arg.Content,
arg.DisplayOrder,
arg.IsActive,
arg.ID,
)
return err
}