GraphQL API and utilities for the rpdata project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

235 lines
5.9 KiB

// Code generated by sqlc. DO NOT EDIT.
// source: characters.sql
package psqlcore
import (
"context"
"github.com/lib/pq"
)
const addCharacterNick = `-- name: AddCharacterNick :exec
UPDATE data_character
SET nicks=append(nicks, $1::text)
WHERE id=$2::text
`
type AddCharacterNickParams struct {
Nick string `json:"nick"`
ID string `json:"id"`
}
func (q *Queries) AddCharacterNick(ctx context.Context, arg AddCharacterNickParams) error {
_, err := q.db.ExecContext(ctx, addCharacterNick, arg.Nick, arg.ID)
return err
}
const deleteCharacter = `-- name: DeleteCharacter :exec
DELETE FROM data_character WHERE id=$1
`
func (q *Queries) DeleteCharacter(ctx context.Context, id string) error {
_, err := q.db.ExecContext(ctx, deleteCharacter, id)
return err
}
const insertCharacter = `-- name: InsertCharacter :exec
INSERT INTO data_character (id, nicks, name, short_name, author, description, ts_vector) VALUES (
$1::text, $2::text[], $3::text,
$4::text, $5::text, $6::text,
to_tsvector(
'english',
$3::text || ' ' || $6::text || ' ' || $5::text || ' '
|| immutable_array_to_string(
$2::text[], ' '
)
)
)
`
type InsertCharacterParams struct {
ID string `json:"id"`
Nicks []string `json:"nicks"`
Name string `json:"name"`
ShortName string `json:"short_name"`
Author string `json:"author"`
Description string `json:"description"`
}
func (q *Queries) InsertCharacter(ctx context.Context, arg InsertCharacterParams) error {
_, err := q.db.ExecContext(ctx, insertCharacter,
arg.ID,
pq.Array(arg.Nicks),
arg.Name,
arg.ShortName,
arg.Author,
arg.Description,
)
return err
}
const removeCharacterNick = `-- name: RemoveCharacterNick :exec
UPDATE data_character
SET nicks=array_remove(nicks, $1::text)
WHERE id=$2::text
`
type RemoveCharacterNickParams struct {
Nick string `json:"nick"`
ID string `json:"id"`
}
func (q *Queries) RemoveCharacterNick(ctx context.Context, arg RemoveCharacterNickParams) error {
_, err := q.db.ExecContext(ctx, removeCharacterNick, arg.Nick, arg.ID)
return err
}
const selectCharacterByID = `-- name: SelectCharacterByID :one
SELECT id, nicks, name, short_name, author, description, ts_vector FROM data_character WHERE id = $1::text
`
func (q *Queries) SelectCharacterByID(ctx context.Context, id string) (DataCharacter, error) {
row := q.db.QueryRowContext(ctx, selectCharacterByID, id)
var i DataCharacter
err := row.Scan(
&i.ID,
pq.Array(&i.Nicks),
&i.Name,
&i.ShortName,
&i.Author,
&i.Description,
&i.TsVector,
)
return i, err
}
const selectCharacterByName = `-- name: SelectCharacterByName :one
SELECT id, nicks, name, short_name, author, description, ts_vector FROM data_character WHERE name = $1::text
`
func (q *Queries) SelectCharacterByName(ctx context.Context, name string) (DataCharacter, error) {
row := q.db.QueryRowContext(ctx, selectCharacterByName, name)
var i DataCharacter
err := row.Scan(
&i.ID,
pq.Array(&i.Nicks),
&i.Name,
&i.ShortName,
&i.Author,
&i.Description,
&i.TsVector,
)
return i, err
}
const selectCharacterByNick = `-- name: SelectCharacterByNick :one
SELECT id, nicks, name, short_name, author, description, ts_vector FROM data_character WHERE nicks <@ ARRAY[$1::text]
`
func (q *Queries) SelectCharacterByNick(ctx context.Context, nick string) (DataCharacter, error) {
row := q.db.QueryRowContext(ctx, selectCharacterByNick, nick)
var i DataCharacter
err := row.Scan(
&i.ID,
pq.Array(&i.Nicks),
&i.Name,
&i.ShortName,
&i.Author,
&i.Description,
&i.TsVector,
)
return i, err
}
const selectCharacters = `-- name: SelectCharacters :many
SELECT id, nicks, name, short_name, author, description, ts_vector FROM data_character
WHERE ($1::bool = false OR id = ANY($2::text[]))
AND ($3::bool = false OR name = ANY($4::text[]))
AND ($5::bool = false OR nicks && ($6::text[]))
AND ($7::bool = false OR author = $8::text)
AND ($9::bool = false OR "ts_vector" @@ to_tsquery($10::text))
LIMIT $11::int
`
type SelectCharactersParams struct {
FilterID bool `json:"filter_id"`
Ids []string `json:"ids"`
FilterName bool `json:"filter_name"`
Names []string `json:"names"`
FilterNick bool `json:"filter_nick"`
Nicks []string `json:"nicks"`
FilterAuthor bool `json:"filter_author"`
Author string `json:"author"`
FilterSearch bool `json:"filter_search"`
Search string `json:"search"`
LimitSize int32 `json:"limit_size"`
}
func (q *Queries) SelectCharacters(ctx context.Context, arg SelectCharactersParams) ([]DataCharacter, error) {
rows, err := q.db.QueryContext(ctx, selectCharacters,
arg.FilterID,
pq.Array(arg.Ids),
arg.FilterName,
pq.Array(arg.Names),
arg.FilterNick,
pq.Array(arg.Nicks),
arg.FilterAuthor,
arg.Author,
arg.FilterSearch,
arg.Search,
arg.LimitSize,
)
if err != nil {
return nil, err
}
defer rows.Close()
items := []DataCharacter{}
for rows.Next() {
var i DataCharacter
if err := rows.Scan(
&i.ID,
pq.Array(&i.Nicks),
&i.Name,
&i.ShortName,
&i.Author,
&i.Description,
&i.TsVector,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const updateCharacter = `-- name: UpdateCharacter :exec
UPDATE data_character
SET name=$1::text,
short_name=$2::text,
description=$3::text
WHERE id=$4::text
`
type UpdateCharacterParams struct {
Name string `json:"name"`
ShortName string `json:"short_name"`
Description string `json:"description"`
ID string `json:"id"`
}
func (q *Queries) UpdateCharacter(ctx context.Context, arg UpdateCharacterParams) error {
_, err := q.db.ExecContext(ctx, updateCharacter,
arg.Name,
arg.ShortName,
arg.Description,
arg.ID,
)
return err
}