468 lines
11 KiB
Go
468 lines
11 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: bots.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
const countBotsByUsername = `-- name: CountBotsByUsername :one
|
|
SELECT COUNT(*) FROM bots
|
|
WHERE ($2::text IS NULL OR username ILIKE '%' || $2 || '%') AND status = $1
|
|
`
|
|
|
|
type CountBotsByUsernameParams struct {
|
|
Status BotStatus `json:"status"`
|
|
Query string `json:"query"`
|
|
}
|
|
|
|
func (q *Queries) CountBotsByUsername(ctx context.Context, arg CountBotsByUsernameParams) (int64, error) {
|
|
row := q.db.QueryRow(ctx, countBotsByUsername, arg.Status, arg.Query)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const createBot = `-- name: CreateBot :one
|
|
INSERT INTO bots (
|
|
id,
|
|
username,
|
|
avatar,
|
|
overview,
|
|
description,
|
|
is_slash,
|
|
install_context,
|
|
guild_count,
|
|
install_count,
|
|
imported_from,
|
|
prefix,
|
|
main_owner_id
|
|
)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)
|
|
RETURNING id, username, avatar, overview, description, is_slash, install_context, guild_count, install_count, imported_from, prefix, created_at, updated_at, status, main_owner_id
|
|
`
|
|
|
|
type CreateBotParams struct {
|
|
ID string `json:"id"`
|
|
Username string `json:"username"`
|
|
Avatar *string `json:"avatar"`
|
|
Overview *string `json:"overview"`
|
|
Description *string `json:"description"`
|
|
IsSlash bool `json:"is_slash"`
|
|
InstallContext InstallContext `json:"install_context"`
|
|
GuildCount *int32 `json:"guild_count"`
|
|
InstallCount *int32 `json:"install_count"`
|
|
ImportedFrom *string `json:"imported_from"`
|
|
Prefix *string `json:"prefix"`
|
|
MainOwnerID *string `json:"main_owner_id"`
|
|
}
|
|
|
|
func (q *Queries) CreateBot(ctx context.Context, arg CreateBotParams) (*Bot, error) {
|
|
row := q.db.QueryRow(ctx, createBot,
|
|
arg.ID,
|
|
arg.Username,
|
|
arg.Avatar,
|
|
arg.Overview,
|
|
arg.Description,
|
|
arg.IsSlash,
|
|
arg.InstallContext,
|
|
arg.GuildCount,
|
|
arg.InstallCount,
|
|
arg.ImportedFrom,
|
|
arg.Prefix,
|
|
arg.MainOwnerID,
|
|
)
|
|
var i Bot
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Username,
|
|
&i.Avatar,
|
|
&i.Overview,
|
|
&i.Description,
|
|
&i.IsSlash,
|
|
&i.InstallContext,
|
|
&i.GuildCount,
|
|
&i.InstallCount,
|
|
&i.ImportedFrom,
|
|
&i.Prefix,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.Status,
|
|
&i.MainOwnerID,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const deleteBot = `-- name: DeleteBot :exec
|
|
DELETE FROM bots
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteBot(ctx context.Context, id string) error {
|
|
_, err := q.db.Exec(ctx, deleteBot, id)
|
|
return err
|
|
}
|
|
|
|
const getBot = `-- name: GetBot :one
|
|
SELECT id, username, avatar, overview, description, is_slash, install_context, guild_count, install_count, imported_from, prefix, created_at, updated_at, status, main_owner_id FROM bots
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetBot(ctx context.Context, id string) (*Bot, error) {
|
|
row := q.db.QueryRow(ctx, getBot, id)
|
|
var i Bot
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Username,
|
|
&i.Avatar,
|
|
&i.Overview,
|
|
&i.Description,
|
|
&i.IsSlash,
|
|
&i.InstallContext,
|
|
&i.GuildCount,
|
|
&i.InstallCount,
|
|
&i.ImportedFrom,
|
|
&i.Prefix,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.Status,
|
|
&i.MainOwnerID,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const getBotByUsername = `-- name: GetBotByUsername :one
|
|
SELECT id, username, avatar, overview, description, is_slash, install_context, guild_count, install_count, imported_from, prefix, created_at, updated_at, status, main_owner_id FROM bots
|
|
WHERE username = $1
|
|
`
|
|
|
|
func (q *Queries) GetBotByUsername(ctx context.Context, username string) (*Bot, error) {
|
|
row := q.db.QueryRow(ctx, getBotByUsername, username)
|
|
var i Bot
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Username,
|
|
&i.Avatar,
|
|
&i.Overview,
|
|
&i.Description,
|
|
&i.IsSlash,
|
|
&i.InstallContext,
|
|
&i.GuildCount,
|
|
&i.InstallCount,
|
|
&i.ImportedFrom,
|
|
&i.Prefix,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.Status,
|
|
&i.MainOwnerID,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const listBots = `-- name: ListBots :many
|
|
SELECT id, username, avatar, overview, description, is_slash, install_context, guild_count, install_count, imported_from, prefix, created_at, updated_at, status, main_owner_id FROM bots
|
|
ORDER BY id
|
|
LIMIT $1
|
|
OFFSET $2
|
|
`
|
|
|
|
type ListBotsParams struct {
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) ListBots(ctx context.Context, arg ListBotsParams) ([]*Bot, error) {
|
|
rows, err := q.db.Query(ctx, listBots, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []*Bot{}
|
|
for rows.Next() {
|
|
var i Bot
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Username,
|
|
&i.Avatar,
|
|
&i.Overview,
|
|
&i.Description,
|
|
&i.IsSlash,
|
|
&i.InstallContext,
|
|
&i.GuildCount,
|
|
&i.InstallCount,
|
|
&i.ImportedFrom,
|
|
&i.Prefix,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.Status,
|
|
&i.MainOwnerID,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, &i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listBotsByOwner = `-- name: ListBotsByOwner :many
|
|
SELECT id, username, avatar, overview, description, is_slash, install_context, guild_count, install_count, imported_from, prefix, created_at, updated_at, status, main_owner_id FROM bots
|
|
WHERE main_owner_id = $1
|
|
ORDER BY id
|
|
LIMIT $2
|
|
OFFSET $3
|
|
`
|
|
|
|
type ListBotsByOwnerParams struct {
|
|
MainOwnerID *string `json:"main_owner_id"`
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) ListBotsByOwner(ctx context.Context, arg ListBotsByOwnerParams) ([]*Bot, error) {
|
|
rows, err := q.db.Query(ctx, listBotsByOwner, arg.MainOwnerID, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []*Bot{}
|
|
for rows.Next() {
|
|
var i Bot
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Username,
|
|
&i.Avatar,
|
|
&i.Overview,
|
|
&i.Description,
|
|
&i.IsSlash,
|
|
&i.InstallContext,
|
|
&i.GuildCount,
|
|
&i.InstallCount,
|
|
&i.ImportedFrom,
|
|
&i.Prefix,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.Status,
|
|
&i.MainOwnerID,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, &i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listBotsByStatus = `-- name: ListBotsByStatus :many
|
|
SELECT id, username, avatar, overview, description, is_slash, install_context, guild_count, install_count, imported_from, prefix, created_at, updated_at, status, main_owner_id FROM bots
|
|
WHERE status = $1
|
|
ORDER BY id
|
|
LIMIT $2
|
|
OFFSET $3
|
|
`
|
|
|
|
type ListBotsByStatusParams struct {
|
|
Status BotStatus `json:"status"`
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) ListBotsByStatus(ctx context.Context, arg ListBotsByStatusParams) ([]*Bot, error) {
|
|
rows, err := q.db.Query(ctx, listBotsByStatus, arg.Status, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []*Bot{}
|
|
for rows.Next() {
|
|
var i Bot
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Username,
|
|
&i.Avatar,
|
|
&i.Overview,
|
|
&i.Description,
|
|
&i.IsSlash,
|
|
&i.InstallContext,
|
|
&i.GuildCount,
|
|
&i.InstallCount,
|
|
&i.ImportedFrom,
|
|
&i.Prefix,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.Status,
|
|
&i.MainOwnerID,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, &i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const searchBotsByUsername = `-- name: SearchBotsByUsername :many
|
|
SELECT id, username, avatar, overview, description, is_slash, install_context, guild_count, install_count, imported_from, prefix, created_at, updated_at, status, main_owner_id FROM bots
|
|
WHERE ($3::text IS NULL OR username ILIKE '%' || $3 || '%')
|
|
ORDER BY created_at DESC
|
|
LIMIT $1
|
|
OFFSET $2
|
|
`
|
|
|
|
type SearchBotsByUsernameParams struct {
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
Query string `json:"query"`
|
|
}
|
|
|
|
func (q *Queries) SearchBotsByUsername(ctx context.Context, arg SearchBotsByUsernameParams) ([]*Bot, error) {
|
|
rows, err := q.db.Query(ctx, searchBotsByUsername, arg.Limit, arg.Offset, arg.Query)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []*Bot{}
|
|
for rows.Next() {
|
|
var i Bot
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Username,
|
|
&i.Avatar,
|
|
&i.Overview,
|
|
&i.Description,
|
|
&i.IsSlash,
|
|
&i.InstallContext,
|
|
&i.GuildCount,
|
|
&i.InstallCount,
|
|
&i.ImportedFrom,
|
|
&i.Prefix,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.Status,
|
|
&i.MainOwnerID,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, &i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const updateBot = `-- name: UpdateBot :one
|
|
UPDATE bots
|
|
SET
|
|
username = coalesce($1, username),
|
|
avatar = coalesce($2, avatar),
|
|
overview = coalesce($3, overview),
|
|
description = coalesce($4, description),
|
|
is_slash = coalesce($5, is_slash),
|
|
install_context = coalesce($6, install_context),
|
|
guild_count = coalesce($7, guild_count),
|
|
install_count = coalesce($8, install_count),
|
|
imported_from = coalesce($9, imported_from),
|
|
prefix = coalesce($10, prefix),
|
|
main_owner_id = coalesce($11, main_owner_id),
|
|
updated_at = now()
|
|
WHERE id = $12
|
|
RETURNING id, username, avatar, overview, description, is_slash, install_context, guild_count, install_count, imported_from, prefix, created_at, updated_at, status, main_owner_id
|
|
`
|
|
|
|
type UpdateBotParams struct {
|
|
Username *string `json:"username"`
|
|
Avatar *string `json:"avatar"`
|
|
Overview *string `json:"overview"`
|
|
Description *string `json:"description"`
|
|
IsSlash *bool `json:"is_slash"`
|
|
InstallContext InstallContext `json:"install_context"`
|
|
GuildCount *int32 `json:"guild_count"`
|
|
InstallCount *int32 `json:"install_count"`
|
|
ImportedFrom *string `json:"imported_from"`
|
|
Prefix *string `json:"prefix"`
|
|
MainOwnerID *string `json:"main_owner_id"`
|
|
ID string `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateBot(ctx context.Context, arg UpdateBotParams) (*Bot, error) {
|
|
row := q.db.QueryRow(ctx, updateBot,
|
|
arg.Username,
|
|
arg.Avatar,
|
|
arg.Overview,
|
|
arg.Description,
|
|
arg.IsSlash,
|
|
arg.InstallContext,
|
|
arg.GuildCount,
|
|
arg.InstallCount,
|
|
arg.ImportedFrom,
|
|
arg.Prefix,
|
|
arg.MainOwnerID,
|
|
arg.ID,
|
|
)
|
|
var i Bot
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Username,
|
|
&i.Avatar,
|
|
&i.Overview,
|
|
&i.Description,
|
|
&i.IsSlash,
|
|
&i.InstallContext,
|
|
&i.GuildCount,
|
|
&i.InstallCount,
|
|
&i.ImportedFrom,
|
|
&i.Prefix,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.Status,
|
|
&i.MainOwnerID,
|
|
)
|
|
return &i, err
|
|
}
|
|
|
|
const updateBotStatus = `-- name: UpdateBotStatus :one
|
|
UPDATE bots
|
|
SET
|
|
status = $2,
|
|
updated_at = now()
|
|
WHERE id = $1
|
|
RETURNING id, username, avatar, overview, description, is_slash, install_context, guild_count, install_count, imported_from, prefix, created_at, updated_at, status, main_owner_id
|
|
`
|
|
|
|
type UpdateBotStatusParams struct {
|
|
ID string `json:"id"`
|
|
Status BotStatus `json:"status"`
|
|
}
|
|
|
|
func (q *Queries) UpdateBotStatus(ctx context.Context, arg UpdateBotStatusParams) (*Bot, error) {
|
|
row := q.db.QueryRow(ctx, updateBotStatus, arg.ID, arg.Status)
|
|
var i Bot
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Username,
|
|
&i.Avatar,
|
|
&i.Overview,
|
|
&i.Description,
|
|
&i.IsSlash,
|
|
&i.InstallContext,
|
|
&i.GuildCount,
|
|
&i.InstallCount,
|
|
&i.ImportedFrom,
|
|
&i.Prefix,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.Status,
|
|
&i.MainOwnerID,
|
|
)
|
|
return &i, err
|
|
}
|