136 lines
2.8 KiB
Go
136 lines
2.8 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|||
|
|
// versions:
|
||
|
|
// sqlc v1.31.1
|
||
|
|
// source: follows.sql
|
||
|
|
|
||
|
|
package database
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"github.com/google/uuid"
|
||
|
|
)
|
||
|
|
|
||
|
|
const createFollow = `-- name: CreateFollow :one
|
||
|
|
WITH inserted_follow as (
|
||
|
|
INSERT INTO follows (id, created_at, updated_at, feed_id, user_id)
|
||
|
|
VALUES (
|
||
|
|
$1,
|
||
|
|
$2,
|
||
|
|
$3,
|
||
|
|
$4,
|
||
|
|
$5
|
||
|
|
)
|
||
|
|
RETURNING id, created_at, updated_at, user_id, feed_id
|
||
|
|
)
|
||
|
|
SELECT inserted_follow.id, inserted_follow.created_at, inserted_follow.updated_at, inserted_follow.user_id, inserted_follow.feed_id,
|
||
|
|
feeds.name as feed_name,
|
||
|
|
users.name as user_name
|
||
|
|
FROM inserted_follow
|
||
|
|
INNER JOIN users
|
||
|
|
ON inserted_follow.user_id = users.id
|
||
|
|
INNER JOIN feeds
|
||
|
|
ON inserted_follow.feed_id = feeds.id
|
||
|
|
`
|
||
|
|
|
||
|
|
type CreateFollowParams struct {
|
||
|
|
ID uuid.UUID
|
||
|
|
CreatedAt time.Time
|
||
|
|
UpdatedAt time.Time
|
||
|
|
FeedID uuid.UUID
|
||
|
|
UserID uuid.UUID
|
||
|
|
}
|
||
|
|
|
||
|
|
type CreateFollowRow struct {
|
||
|
|
ID uuid.UUID
|
||
|
|
CreatedAt time.Time
|
||
|
|
UpdatedAt time.Time
|
||
|
|
UserID uuid.UUID
|
||
|
|
FeedID uuid.UUID
|
||
|
|
FeedName string
|
||
|
|
UserName string
|
||
|
|
}
|
||
|
|
|
||
|
|
func (q *Queries) CreateFollow(ctx context.Context, arg CreateFollowParams) (CreateFollowRow, error) {
|
||
|
|
row := q.db.QueryRowContext(ctx, createFollow,
|
||
|
|
arg.ID,
|
||
|
|
arg.CreatedAt,
|
||
|
|
arg.UpdatedAt,
|
||
|
|
arg.FeedID,
|
||
|
|
arg.UserID,
|
||
|
|
)
|
||
|
|
var i CreateFollowRow
|
||
|
|
err := row.Scan(
|
||
|
|
&i.ID,
|
||
|
|
&i.CreatedAt,
|
||
|
|
&i.UpdatedAt,
|
||
|
|
&i.UserID,
|
||
|
|
&i.FeedID,
|
||
|
|
&i.FeedName,
|
||
|
|
&i.UserName,
|
||
|
|
)
|
||
|
|
return i, err
|
||
|
|
}
|
||
|
|
|
||
|
|
const deleteFollowForUser = `-- name: DeleteFollowForUser :exec
|
||
|
|
DELETE FROM follows
|
||
|
|
WHERE feed_id = $1 AND user_id = $2
|
||
|
|
`
|
||
|
|
|
||
|
|
type DeleteFollowForUserParams struct {
|
||
|
|
FeedID uuid.UUID
|
||
|
|
UserID uuid.UUID
|
||
|
|
}
|
||
|
|
|
||
|
|
func (q *Queries) DeleteFollowForUser(ctx context.Context, arg DeleteFollowForUserParams) error {
|
||
|
|
_, err := q.db.ExecContext(ctx, deleteFollowForUser, arg.FeedID, arg.UserID)
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
const getFollowsForUser = `-- name: GetFollowsForUser :many
|
||
|
|
SELECT follows.id, follows.created_at, follows.updated_at, follows.user_id, follows.feed_id, feeds.name as feed_name FROM follows
|
||
|
|
INNER JOIN feeds
|
||
|
|
ON follows.feed_id = feeds.id
|
||
|
|
WHERE follows.user_id = $1
|
||
|
|
`
|
||
|
|
|
||
|
|
type GetFollowsForUserRow struct {
|
||
|
|
ID uuid.UUID
|
||
|
|
CreatedAt time.Time
|
||
|
|
UpdatedAt time.Time
|
||
|
|
UserID uuid.UUID
|
||
|
|
FeedID uuid.UUID
|
||
|
|
FeedName string
|
||
|
|
}
|
||
|
|
|
||
|
|
func (q *Queries) GetFollowsForUser(ctx context.Context, userID uuid.UUID) ([]GetFollowsForUserRow, error) {
|
||
|
|
rows, err := q.db.QueryContext(ctx, getFollowsForUser, userID)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
defer rows.Close()
|
||
|
|
var items []GetFollowsForUserRow
|
||
|
|
for rows.Next() {
|
||
|
|
var i GetFollowsForUserRow
|
||
|
|
if err := rows.Scan(
|
||
|
|
&i.ID,
|
||
|
|
&i.CreatedAt,
|
||
|
|
&i.UpdatedAt,
|
||
|
|
&i.UserID,
|
||
|
|
&i.FeedID,
|
||
|
|
&i.FeedName,
|
||
|
|
); err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
items = append(items, i)
|
||
|
|
}
|
||
|
|
if err := rows.Close(); err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
if err := rows.Err(); err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
return items, nil
|
||
|
|
}
|