62 lines
1.3 KiB
Go
62 lines
1.3 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: votes.sql
|
|
|
|
package sqlc
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
const deleteVote = `-- name: DeleteVote :exec
|
|
DELETE FROM votes
|
|
WHERE user_id = $1 AND question_id = $2
|
|
`
|
|
|
|
type DeleteVoteParams struct {
|
|
UserID string
|
|
QuestionID string
|
|
}
|
|
|
|
func (q *Queries) DeleteVote(ctx context.Context, arg DeleteVoteParams) error {
|
|
_, err := q.db.ExecContext(ctx, deleteVote, arg.UserID, arg.QuestionID)
|
|
return err
|
|
}
|
|
|
|
const getVote = `-- name: GetVote :one
|
|
SELECT value
|
|
FROM votes
|
|
WHERE user_id = $1 AND question_id = $2
|
|
`
|
|
|
|
type GetVoteParams struct {
|
|
UserID string
|
|
QuestionID string
|
|
}
|
|
|
|
func (q *Queries) GetVote(ctx context.Context, arg GetVoteParams) (int32, error) {
|
|
row := q.db.QueryRowContext(ctx, getVote, arg.UserID, arg.QuestionID)
|
|
var value int32
|
|
err := row.Scan(&value)
|
|
return value, err
|
|
}
|
|
|
|
const upsertVote = `-- name: UpsertVote :exec
|
|
INSERT INTO votes (user_id, question_id, value)
|
|
VALUES ($1, $2, $3)
|
|
ON CONFLICT (user_id, question_id) DO UPDATE
|
|
SET value = excluded.value
|
|
`
|
|
|
|
type UpsertVoteParams struct {
|
|
UserID string
|
|
QuestionID string
|
|
Value int32
|
|
}
|
|
|
|
func (q *Queries) UpsertVote(ctx context.Context, arg UpsertVoteParams) error {
|
|
_, err := q.db.ExecContext(ctx, upsertVote, arg.UserID, arg.QuestionID, arg.Value)
|
|
return err
|
|
}
|