Enshi/enshi_back/db/go_queries/post_votes_queries.sql.go
2024-11-04 12:59:16 +03:00

84 lines
2.0 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.27.0
// source: post_votes_queries.sql
package db_repo
import (
"context"
)
const createPostVote = `-- name: CreatePostVote :one
INSERT INTO public.post_votes
(post_id, user_id, vote)
VALUES($1, $2, $3)
RETURNING post_id, user_id, vote
`
type CreatePostVoteParams struct {
PostID int64 `json:"post_id"`
UserID int64 `json:"user_id"`
Vote bool `json:"vote"`
}
func (q *Queries) CreatePostVote(ctx context.Context, arg CreatePostVoteParams) (PostVote, error) {
row := q.db.QueryRow(ctx, createPostVote, arg.PostID, arg.UserID, arg.Vote)
var i PostVote
err := row.Scan(&i.PostID, &i.UserID, &i.Vote)
return i, err
}
const deletePostVote = `-- name: DeletePostVote :exec
DELETE FROM public.post_votes
WHERE post_id=$1 AND user_id=$2
`
type DeletePostVoteParams struct {
PostID int64 `json:"post_id"`
UserID int64 `json:"user_id"`
}
func (q *Queries) DeletePostVote(ctx context.Context, arg DeletePostVoteParams) error {
_, err := q.db.Exec(ctx, deletePostVote, arg.PostID, arg.UserID)
return err
}
const getPostVote = `-- name: GetPostVote :one
SELECT vote
FROM public.post_votes p_v
WHERE p_v.user_id = $1 and p_v.post_id = $2
`
type GetPostVoteParams struct {
UserID int64 `json:"user_id"`
PostID int64 `json:"post_id"`
}
func (q *Queries) GetPostVote(ctx context.Context, arg GetPostVoteParams) (bool, error) {
row := q.db.QueryRow(ctx, getPostVote, arg.UserID, arg.PostID)
var vote bool
err := row.Scan(&vote)
return vote, err
}
const updateVote = `-- name: UpdateVote :one
UPDATE public.post_votes
SET vote=$1
WHERE post_id=$2 AND user_id=$3
RETURNING post_id, user_id, vote
`
type UpdateVoteParams struct {
Vote bool `json:"vote"`
PostID int64 `json:"post_id"`
UserID int64 `json:"user_id"`
}
func (q *Queries) UpdateVote(ctx context.Context, arg UpdateVoteParams) (PostVote, error) {
row := q.db.QueryRow(ctx, updateVote, arg.Vote, arg.PostID, arg.UserID)
var i PostVote
err := row.Scan(&i.PostID, &i.UserID, &i.Vote)
return i, err
}