// 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) ON CONFLICT (user_id, post_id) DO UPDATE SET vote = $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 getPostVotes = `-- name: GetPostVotes :one SELECT count (*) FILTER (WHERE vote = TRUE) as upvotes, count (*) FILTER (WHERE vote = FALSE) as downvotes FROM public.post_votes WHERE post_id = $1 ` type GetPostVotesRow struct { Upvotes int64 `json:"upvotes"` Downvotes int64 `json:"downvotes"` } func (q *Queries) GetPostVotes(ctx context.Context, postID int64) (GetPostVotesRow, error) { row := q.db.QueryRow(ctx, getPostVotes, postID) var i GetPostVotesRow err := row.Scan(&i.Upvotes, &i.Downvotes) return i, 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 }