157 lines
3.5 KiB
Go
157 lines
3.5 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: entities.sql
|
|
|
|
package sqlc
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const createEntity = `-- name: CreateEntity :one
|
|
INSERT INTO entities (
|
|
name, description, thumbnail_url
|
|
) VALUES (
|
|
$1, $2, $3
|
|
)
|
|
RETURNING id, name, description, thumbnail_url, is_deleted, created_at, updated_at
|
|
`
|
|
|
|
type CreateEntityParams struct {
|
|
Name string `json:"name"`
|
|
Description pgtype.Text `json:"description"`
|
|
ThumbnailUrl pgtype.Text `json:"thumbnail_url"`
|
|
}
|
|
|
|
func (q *Queries) CreateEntity(ctx context.Context, arg CreateEntityParams) (Entity, error) {
|
|
row := q.db.QueryRow(ctx, createEntity, arg.Name, arg.Description, arg.ThumbnailUrl)
|
|
var i Entity
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.ThumbnailUrl,
|
|
&i.IsDeleted,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteEntity = `-- name: DeleteEntity :exec
|
|
UPDATE entities
|
|
SET
|
|
is_deleted = true
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteEntity(ctx context.Context, id pgtype.UUID) error {
|
|
_, err := q.db.Exec(ctx, deleteEntity, id)
|
|
return err
|
|
}
|
|
|
|
const getEntityById = `-- name: GetEntityById :one
|
|
SELECT id, name, description, thumbnail_url, is_deleted, created_at, updated_at
|
|
FROM entities
|
|
WHERE id = $1 AND is_deleted = false
|
|
`
|
|
|
|
func (q *Queries) GetEntityById(ctx context.Context, id pgtype.UUID) (Entity, error) {
|
|
row := q.db.QueryRow(ctx, getEntityById, id)
|
|
var i Entity
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.ThumbnailUrl,
|
|
&i.IsDeleted,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const searchEntities = `-- name: SearchEntities :many
|
|
SELECT id, name, description, thumbnail_url, is_deleted, created_at, updated_at
|
|
FROM entities
|
|
WHERE is_deleted = false
|
|
AND name ILIKE '%' || $1::text || '%'
|
|
AND ($2::uuid IS NULL OR id < $2::uuid)
|
|
ORDER BY id DESC
|
|
LIMIT $3
|
|
`
|
|
|
|
type SearchEntitiesParams struct {
|
|
Name string `json:"name"`
|
|
CursorID pgtype.UUID `json:"cursor_id"`
|
|
LimitCount int32 `json:"limit_count"`
|
|
}
|
|
|
|
func (q *Queries) SearchEntities(ctx context.Context, arg SearchEntitiesParams) ([]Entity, error) {
|
|
rows, err := q.db.Query(ctx, searchEntities, arg.Name, arg.CursorID, arg.LimitCount)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []Entity{}
|
|
for rows.Next() {
|
|
var i Entity
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.ThumbnailUrl,
|
|
&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 updateEntity = `-- name: UpdateEntity :one
|
|
UPDATE entities
|
|
SET
|
|
name = COALESCE($1, name),
|
|
description = COALESCE($2, description),
|
|
thumbnail_url = COALESCE($3, thumbnail_url)
|
|
WHERE id = $4 AND is_deleted = false
|
|
RETURNING id, name, description, thumbnail_url, is_deleted, created_at, updated_at
|
|
`
|
|
|
|
type UpdateEntityParams struct {
|
|
Name pgtype.Text `json:"name"`
|
|
Description pgtype.Text `json:"description"`
|
|
ThumbnailUrl pgtype.Text `json:"thumbnail_url"`
|
|
ID pgtype.UUID `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateEntity(ctx context.Context, arg UpdateEntityParams) (Entity, error) {
|
|
row := q.db.QueryRow(ctx, updateEntity,
|
|
arg.Name,
|
|
arg.Description,
|
|
arg.ThumbnailUrl,
|
|
arg.ID,
|
|
)
|
|
var i Entity
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.Description,
|
|
&i.ThumbnailUrl,
|
|
&i.IsDeleted,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|