127 lines
2.9 KiB
Go
127 lines
2.9 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: votes.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
const canVoteAgain = `-- name: CanVoteAgain :one
|
|
SELECT can_vote_again($1, $2)
|
|
`
|
|
|
|
type CanVoteAgainParams struct {
|
|
UserID string `json:"user_id"`
|
|
BotID string `json:"bot_id"`
|
|
}
|
|
|
|
func (q *Queries) CanVoteAgain(ctx context.Context, arg CanVoteAgainParams) (bool, error) {
|
|
row := q.db.QueryRow(ctx, canVoteAgain, arg.UserID, arg.BotID)
|
|
var can_vote_again bool
|
|
err := row.Scan(&can_vote_again)
|
|
return can_vote_again, err
|
|
}
|
|
|
|
const countVotesByBot = `-- name: CountVotesByBot :one
|
|
SELECT count(*) FROM votes
|
|
WHERE bot_id = $1
|
|
`
|
|
|
|
func (q *Queries) CountVotesByBot(ctx context.Context, botID string) (int64, error) {
|
|
row := q.db.QueryRow(ctx, countVotesByBot, botID)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const createVote = `-- name: CreateVote :one
|
|
INSERT INTO votes (user_id, bot_id)
|
|
VALUES ($1, $2)
|
|
RETURNING user_id, bot_id, voted_at
|
|
`
|
|
|
|
type CreateVoteParams struct {
|
|
UserID string `json:"user_id"`
|
|
BotID string `json:"bot_id"`
|
|
}
|
|
|
|
func (q *Queries) CreateVote(ctx context.Context, arg CreateVoteParams) (*Vote, error) {
|
|
row := q.db.QueryRow(ctx, createVote, arg.UserID, arg.BotID)
|
|
var i Vote
|
|
err := row.Scan(&i.UserID, &i.BotID, &i.VotedAt)
|
|
return &i, err
|
|
}
|
|
|
|
const getVote = `-- name: GetVote :one
|
|
SELECT user_id, bot_id, voted_at FROM votes
|
|
WHERE user_id = $1 AND bot_id = $2
|
|
ORDER BY voted_at DESC
|
|
LIMIT 1
|
|
`
|
|
|
|
type GetVoteParams struct {
|
|
UserID string `json:"user_id"`
|
|
BotID string `json:"bot_id"`
|
|
}
|
|
|
|
func (q *Queries) GetVote(ctx context.Context, arg GetVoteParams) (*Vote, error) {
|
|
row := q.db.QueryRow(ctx, getVote, arg.UserID, arg.BotID)
|
|
var i Vote
|
|
err := row.Scan(&i.UserID, &i.BotID, &i.VotedAt)
|
|
return &i, err
|
|
}
|
|
|
|
const listVotesByBot = `-- name: ListVotesByBot :many
|
|
SELECT user_id, bot_id, voted_at FROM votes
|
|
WHERE bot_id = $1
|
|
ORDER BY voted_at DESC
|
|
`
|
|
|
|
func (q *Queries) ListVotesByBot(ctx context.Context, botID string) ([]*Vote, error) {
|
|
rows, err := q.db.Query(ctx, listVotesByBot, botID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []*Vote{}
|
|
for rows.Next() {
|
|
var i Vote
|
|
if err := rows.Scan(&i.UserID, &i.BotID, &i.VotedAt); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, &i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listVotesByUser = `-- name: ListVotesByUser :many
|
|
SELECT user_id, bot_id, voted_at FROM votes
|
|
WHERE user_id = $1
|
|
ORDER BY voted_at DESC
|
|
`
|
|
|
|
func (q *Queries) ListVotesByUser(ctx context.Context, userID string) ([]*Vote, error) {
|
|
rows, err := q.db.Query(ctx, listVotesByUser, userID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []*Vote{}
|
|
for rows.Next() {
|
|
var i Vote
|
|
if err := rows.Scan(&i.UserID, &i.BotID, &i.VotedAt); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, &i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|