141 lines
2.7 KiB
Go
141 lines
2.7 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.21.0
|
|
// source: posts.sql
|
|
|
|
package database
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"time"
|
|
)
|
|
|
|
const createPost = `-- name: CreatePost :one
|
|
INSERT INTO posts (
|
|
created_at,
|
|
updated_at,
|
|
title,
|
|
description,
|
|
published_at,
|
|
url,
|
|
feed_id)
|
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
RETURNING id, created_at, updated_at, title, description, published_at, url, feed_id
|
|
`
|
|
|
|
type CreatePostParams struct {
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
Title string
|
|
Description sql.NullString
|
|
PublishedAt time.Time
|
|
Url string
|
|
FeedID int64
|
|
}
|
|
|
|
func (q *Queries) CreatePost(ctx context.Context, arg CreatePostParams) (Post, error) {
|
|
row := q.db.QueryRowContext(ctx, createPost,
|
|
arg.CreatedAt,
|
|
arg.UpdatedAt,
|
|
arg.Title,
|
|
arg.Description,
|
|
arg.PublishedAt,
|
|
arg.Url,
|
|
arg.FeedID,
|
|
)
|
|
var i Post
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.PublishedAt,
|
|
&i.Url,
|
|
&i.FeedID,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getPosts = `-- name: GetPosts :many
|
|
SELECT id, created_at, updated_at, title, description, published_at, url, feed_id FROM posts
|
|
`
|
|
|
|
func (q *Queries) GetPosts(ctx context.Context) ([]Post, error) {
|
|
rows, err := q.db.QueryContext(ctx, getPosts)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Post
|
|
for rows.Next() {
|
|
var i Post
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.PublishedAt,
|
|
&i.Url,
|
|
&i.FeedID,
|
|
); 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
|
|
}
|
|
|
|
const getPostsForUser = `-- name: GetPostsForUser :many
|
|
SELECT posts.id, posts.created_at, posts.updated_at, posts.title, posts.description, posts.published_at, posts.url, posts.feed_id FROM posts
|
|
JOIN feed_follows ON posts.feed_id = feed_follows.id
|
|
WHERE feed_follows.user_id = ?
|
|
ORDER BY posts.published_at DESC
|
|
LIMIT ?
|
|
`
|
|
|
|
type GetPostsForUserParams struct {
|
|
UserID int64
|
|
Limit int64
|
|
}
|
|
|
|
func (q *Queries) GetPostsForUser(ctx context.Context, arg GetPostsForUserParams) ([]Post, error) {
|
|
rows, err := q.db.QueryContext(ctx, getPostsForUser, arg.UserID, arg.Limit)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Post
|
|
for rows.Next() {
|
|
var i Post
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.Title,
|
|
&i.Description,
|
|
&i.PublishedAt,
|
|
&i.Url,
|
|
&i.FeedID,
|
|
); 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
|
|
}
|