104 lines
2.7 KiB
Go
104 lines
2.7 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.27.0
|
|
// source: bookmarks_queries.sql
|
|
|
|
package db_repo
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const createBookmark = `-- name: CreateBookmark :one
|
|
INSERT INTO public.bookmarks
|
|
(user_id, post_id, bookmarked_at)
|
|
VALUES($1, $2, CURRENT_TIMESTAMP)
|
|
RETURNING user_id, post_id, bookmarked_at
|
|
`
|
|
|
|
type CreateBookmarkParams struct {
|
|
UserID int64 `json:"user_id"`
|
|
PostID int64 `json:"post_id"`
|
|
}
|
|
|
|
func (q *Queries) CreateBookmark(ctx context.Context, arg CreateBookmarkParams) (Bookmark, error) {
|
|
row := q.db.QueryRow(ctx, createBookmark, arg.UserID, arg.PostID)
|
|
var i Bookmark
|
|
err := row.Scan(&i.UserID, &i.PostID, &i.BookmarkedAt)
|
|
return i, err
|
|
}
|
|
|
|
const deleteBookmark = `-- name: DeleteBookmark :exec
|
|
DELETE FROM public.bookmarks
|
|
WHERE user_id=$1 AND post_id=$2
|
|
`
|
|
|
|
type DeleteBookmarkParams struct {
|
|
UserID int64 `json:"user_id"`
|
|
PostID int64 `json:"post_id"`
|
|
}
|
|
|
|
func (q *Queries) DeleteBookmark(ctx context.Context, arg DeleteBookmarkParams) error {
|
|
_, err := q.db.Exec(ctx, deleteBookmark, arg.UserID, arg.PostID)
|
|
return err
|
|
}
|
|
|
|
const getBookmarkTimestamp = `-- name: GetBookmarkTimestamp :one
|
|
SELECT bookmarked_at
|
|
FROM public.bookmarks bookmarks
|
|
where bookmarks.post_id = $1 and bookmarks.user_id = $2
|
|
`
|
|
|
|
type GetBookmarkTimestampParams struct {
|
|
PostID int64 `json:"post_id"`
|
|
UserID int64 `json:"user_id"`
|
|
}
|
|
|
|
func (q *Queries) GetBookmarkTimestamp(ctx context.Context, arg GetBookmarkTimestampParams) (pgtype.Timestamp, error) {
|
|
row := q.db.QueryRow(ctx, getBookmarkTimestamp, arg.PostID, arg.UserID)
|
|
var bookmarked_at pgtype.Timestamp
|
|
err := row.Scan(&bookmarked_at)
|
|
return bookmarked_at, err
|
|
}
|
|
|
|
const getBookmarksByUserId = `-- name: GetBookmarksByUserId :many
|
|
SELECT user_id, post_id, bookmarked_at
|
|
FROM public.bookmarks bookmarks
|
|
where bookmarks.user_id = $1
|
|
`
|
|
|
|
func (q *Queries) GetBookmarksByUserId(ctx context.Context, userID int64) ([]Bookmark, error) {
|
|
rows, err := q.db.Query(ctx, getBookmarksByUserId, userID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Bookmark
|
|
for rows.Next() {
|
|
var i Bookmark
|
|
if err := rows.Scan(&i.UserID, &i.PostID, &i.BookmarkedAt); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getCountOfBookmarksByPostId = `-- name: GetCountOfBookmarksByPostId :one
|
|
SELECT COUNT(*)
|
|
FROM public.bookmarks bookmarks
|
|
where bookmarks.post_id = $1
|
|
`
|
|
|
|
func (q *Queries) GetCountOfBookmarksByPostId(ctx context.Context, postID int64) (int64, error) {
|
|
row := q.db.QueryRow(ctx, getCountOfBookmarksByPostId, postID)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|