All checks were successful
Build and Release / release (push) Successful in 1m15s
235 lines
5.0 KiB
Go
235 lines
5.0 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: wiki.sql
|
|
|
|
package sqlc
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const bulkDeleteEntityWikisByEntityId = `-- name: BulkDeleteEntityWikisByEntityId :many
|
|
DELETE FROM entity_wikis
|
|
WHERE entity_id = $1
|
|
RETURNING wiki_id
|
|
`
|
|
|
|
func (q *Queries) BulkDeleteEntityWikisByEntityId(ctx context.Context, entityID pgtype.UUID) ([]pgtype.UUID, error) {
|
|
rows, err := q.db.Query(ctx, bulkDeleteEntityWikisByEntityId, entityID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []pgtype.UUID{}
|
|
for rows.Next() {
|
|
var wiki_id pgtype.UUID
|
|
if err := rows.Scan(&wiki_id); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, wiki_id)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const createEntityWikis = `-- name: CreateEntityWikis :exec
|
|
INSERT INTO entity_wikis (
|
|
entity_id, wiki_id
|
|
)
|
|
SELECT $1, unnest($2::uuid[])
|
|
`
|
|
|
|
type CreateEntityWikisParams struct {
|
|
EntityID pgtype.UUID `json:"entity_id"`
|
|
WikiIds []pgtype.UUID `json:"wiki_ids"`
|
|
}
|
|
|
|
func (q *Queries) CreateEntityWikis(ctx context.Context, arg CreateEntityWikisParams) error {
|
|
_, err := q.db.Exec(ctx, createEntityWikis, arg.EntityID, arg.WikiIds)
|
|
return err
|
|
}
|
|
|
|
const createWiki = `-- name: CreateWiki :one
|
|
INSERT INTO wikis (
|
|
title, content
|
|
) VALUES (
|
|
$1, $2
|
|
)
|
|
RETURNING id, title, content, is_deleted, created_at, updated_at
|
|
`
|
|
|
|
type CreateWikiParams struct {
|
|
Title pgtype.Text `json:"title"`
|
|
Content pgtype.Text `json:"content"`
|
|
}
|
|
|
|
func (q *Queries) CreateWiki(ctx context.Context, arg CreateWikiParams) (Wiki, error) {
|
|
row := q.db.QueryRow(ctx, createWiki, arg.Title, arg.Content)
|
|
var i Wiki
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Title,
|
|
&i.Content,
|
|
&i.IsDeleted,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteWiki = `-- name: DeleteWiki :exec
|
|
UPDATE wikis
|
|
SET
|
|
is_deleted = true
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteWiki(ctx context.Context, id pgtype.UUID) error {
|
|
_, err := q.db.Exec(ctx, deleteWiki, id)
|
|
return err
|
|
}
|
|
|
|
const getWikiById = `-- name: GetWikiById :one
|
|
SELECT id, title, content, is_deleted, created_at, updated_at
|
|
FROM wikis
|
|
WHERE id = $1 AND is_deleted = false
|
|
`
|
|
|
|
func (q *Queries) GetWikiById(ctx context.Context, id pgtype.UUID) (Wiki, error) {
|
|
row := q.db.QueryRow(ctx, getWikiById, id)
|
|
var i Wiki
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Title,
|
|
&i.Content,
|
|
&i.IsDeleted,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getWikisByIDs = `-- name: GetWikisByIDs :many
|
|
SELECT id, title, content, is_deleted, created_at, updated_at FROM wikis WHERE id = ANY($1::uuid[]) AND is_deleted = false
|
|
`
|
|
|
|
func (q *Queries) GetWikisByIDs(ctx context.Context, dollar_1 []pgtype.UUID) ([]Wiki, error) {
|
|
rows, err := q.db.Query(ctx, getWikisByIDs, dollar_1)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Wiki{}
|
|
for rows.Next() {
|
|
var i Wiki
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Title,
|
|
&i.Content,
|
|
&i.IsDeleted,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const searchWikis = `-- name: SearchWikis :many
|
|
SELECT w.id, w.title, w.content, w.is_deleted, w.created_at, w.updated_at
|
|
FROM wikis w
|
|
WHERE w.is_deleted = false
|
|
AND w.title ILIKE '%' || $1::text || '%'
|
|
AND (
|
|
$2::uuid IS NULL OR
|
|
EXISTS (
|
|
SELECT 1
|
|
FROM entity_wikis ew
|
|
WHERE ew.wiki_id = w.id
|
|
AND ew.entity_id = $2::uuid
|
|
)
|
|
)
|
|
AND ($3::uuid IS NULL OR w.id < $3::uuid)
|
|
|
|
ORDER BY w.id DESC
|
|
LIMIT $4
|
|
`
|
|
|
|
type SearchWikisParams struct {
|
|
Title string `json:"title"`
|
|
EntityID pgtype.UUID `json:"entity_id"`
|
|
CursorID pgtype.UUID `json:"cursor_id"`
|
|
LimitCount int32 `json:"limit_count"`
|
|
}
|
|
|
|
func (q *Queries) SearchWikis(ctx context.Context, arg SearchWikisParams) ([]Wiki, error) {
|
|
rows, err := q.db.Query(ctx, searchWikis,
|
|
arg.Title,
|
|
arg.EntityID,
|
|
arg.CursorID,
|
|
arg.LimitCount,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Wiki{}
|
|
for rows.Next() {
|
|
var i Wiki
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Title,
|
|
&i.Content,
|
|
&i.IsDeleted,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const updateWiki = `-- name: UpdateWiki :one
|
|
UPDATE wikis
|
|
SET
|
|
title = COALESCE($1, title),
|
|
content = COALESCE($2, content)
|
|
WHERE id = $3 AND is_deleted = false
|
|
RETURNING id, title, content, is_deleted, created_at, updated_at
|
|
`
|
|
|
|
type UpdateWikiParams struct {
|
|
Title pgtype.Text `json:"title"`
|
|
Content pgtype.Text `json:"content"`
|
|
ID pgtype.UUID `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateWiki(ctx context.Context, arg UpdateWikiParams) (Wiki, error) {
|
|
row := q.db.QueryRow(ctx, updateWiki, arg.Title, arg.Content, arg.ID)
|
|
var i Wiki
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Title,
|
|
&i.Content,
|
|
&i.IsDeleted,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|