// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.29.0 // source: articles.sql package db import ( "context" ) const checkArticleExists = `-- name: CheckArticleExists :one SELECT EXISTS( SELECT 1 FROM articles WHERE feed_id = ? AND guid = ? ) as article_exists ` type CheckArticleExistsParams struct { FeedID int64 Guid string } func (q *Queries) CheckArticleExists(ctx context.Context, arg CheckArticleExistsParams) (int64, error) { row := q.db.QueryRowContext(ctx, checkArticleExists, arg.FeedID, arg.Guid) var article_exists int64 err := row.Scan(&article_exists) return article_exists, err } const createArticle = `-- name: CreateArticle :one INSERT INTO articles (feed_id, guid, title, url, is_read) VALUES (?, ?, ?, ?, ?) RETURNING id, feed_id, guid, title, url, is_read ` type CreateArticleParams struct { FeedID int64 Guid string Title string Url string IsRead int64 } func (q *Queries) CreateArticle(ctx context.Context, arg CreateArticleParams) (Article, error) { row := q.db.QueryRowContext(ctx, createArticle, arg.FeedID, arg.Guid, arg.Title, arg.Url, arg.IsRead, ) var i Article err := row.Scan( &i.ID, &i.FeedID, &i.Guid, &i.Title, &i.Url, &i.IsRead, ) return i, err } const deleteArticlesByFeed = `-- name: DeleteArticlesByFeed :exec DELETE FROM articles WHERE feed_id = ? ` func (q *Queries) DeleteArticlesByFeed(ctx context.Context, feedID int64) error { _, err := q.db.ExecContext(ctx, deleteArticlesByFeed, feedID) return err } const getArticle = `-- name: GetArticle :one SELECT a.id, a.feed_id, a.guid, a.title, a.url, a.is_read, f.id as feed_id_2, f.url as feed_url, f.title as feed_title, f.is_subscribed as feed_is_subscribed FROM articles AS a INNER JOIN feeds AS f ON a.feed_id = f.id WHERE a.id = ? AND f.user_id = ? ` type GetArticleParams struct { ID int64 UserID int64 } type GetArticleRow struct { ID int64 FeedID int64 Guid string Title string Url string IsRead int64 FeedID2 int64 FeedUrl string FeedTitle string FeedIsSubscribed int64 } func (q *Queries) GetArticle(ctx context.Context, arg GetArticleParams) (GetArticleRow, error) { row := q.db.QueryRowContext(ctx, getArticle, arg.ID, arg.UserID) var i GetArticleRow err := row.Scan( &i.ID, &i.FeedID, &i.Guid, &i.Title, &i.Url, &i.IsRead, &i.FeedID2, &i.FeedUrl, &i.FeedTitle, &i.FeedIsSubscribed, ) return i, err } const getArticleGUIDsByFeed = `-- name: GetArticleGUIDsByFeed :many SELECT guid FROM articles WHERE feed_id = ? ` func (q *Queries) GetArticleGUIDsByFeed(ctx context.Context, feedID int64) ([]string, error) { rows, err := q.db.QueryContext(ctx, getArticleGUIDsByFeed, feedID) if err != nil { return nil, err } defer rows.Close() items := []string{} for rows.Next() { var guid string if err := rows.Scan(&guid); err != nil { return nil, err } items = append(items, guid) } if err := rows.Close(); err != nil { return nil, err } if err := rows.Err(); err != nil { return nil, err } return items, nil } const getArticlesByFeed = `-- name: GetArticlesByFeed :many SELECT id, feed_id, guid, title, url, is_read FROM articles WHERE feed_id = ? ORDER BY id DESC ` func (q *Queries) GetArticlesByFeed(ctx context.Context, feedID int64) ([]Article, error) { rows, err := q.db.QueryContext(ctx, getArticlesByFeed, feedID) if err != nil { return nil, err } defer rows.Close() items := []Article{} for rows.Next() { var i Article if err := rows.Scan( &i.ID, &i.FeedID, &i.Guid, &i.Title, &i.Url, &i.IsRead, ); 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 getReadArticles = `-- name: GetReadArticles :many SELECT a.id, a.feed_id, a.guid, a.title, a.url, a.is_read, f.id as feed_id_2, f.url as feed_url, f.title as feed_title, f.is_subscribed as feed_is_subscribed FROM articles AS a INNER JOIN feeds AS f ON a.feed_id = f.id WHERE a.is_read = 1 AND f.is_subscribed = 1 AND f.user_id = ? ORDER BY a.id DESC LIMIT 100 ` type GetReadArticlesRow struct { ID int64 FeedID int64 Guid string Title string Url string IsRead int64 FeedID2 int64 FeedUrl string FeedTitle string FeedIsSubscribed int64 } func (q *Queries) GetReadArticles(ctx context.Context, userID int64) ([]GetReadArticlesRow, error) { rows, err := q.db.QueryContext(ctx, getReadArticles, userID) if err != nil { return nil, err } defer rows.Close() items := []GetReadArticlesRow{} for rows.Next() { var i GetReadArticlesRow if err := rows.Scan( &i.ID, &i.FeedID, &i.Guid, &i.Title, &i.Url, &i.IsRead, &i.FeedID2, &i.FeedUrl, &i.FeedTitle, &i.FeedIsSubscribed, ); 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 getUnreadArticles = `-- name: GetUnreadArticles :many SELECT a.id, a.feed_id, a.guid, a.title, a.url, a.is_read, f.id as feed_id_2, f.url as feed_url, f.title as feed_title, f.is_subscribed as feed_is_subscribed FROM articles AS a INNER JOIN feeds AS f ON a.feed_id = f.id WHERE a.is_read = 0 AND f.is_subscribed = 1 AND f.user_id = ? ORDER BY a.id DESC LIMIT 100 ` type GetUnreadArticlesRow struct { ID int64 FeedID int64 Guid string Title string Url string IsRead int64 FeedID2 int64 FeedUrl string FeedTitle string FeedIsSubscribed int64 } func (q *Queries) GetUnreadArticles(ctx context.Context, userID int64) ([]GetUnreadArticlesRow, error) { rows, err := q.db.QueryContext(ctx, getUnreadArticles, userID) if err != nil { return nil, err } defer rows.Close() items := []GetUnreadArticlesRow{} for rows.Next() { var i GetUnreadArticlesRow if err := rows.Scan( &i.ID, &i.FeedID, &i.Guid, &i.Title, &i.Url, &i.IsRead, &i.FeedID2, &i.FeedUrl, &i.FeedTitle, &i.FeedIsSubscribed, ); 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 markFeedArticlesRead = `-- name: MarkFeedArticlesRead :exec UPDATE articles SET is_read = 1 WHERE feed_id = ? ` func (q *Queries) MarkFeedArticlesRead(ctx context.Context, feedID int64) error { _, err := q.db.ExecContext(ctx, markFeedArticlesRead, feedID) return err } const markFeedArticlesUnread = `-- name: MarkFeedArticlesUnread :exec UPDATE articles SET is_read = 0 WHERE feed_id = ? ` func (q *Queries) MarkFeedArticlesUnread(ctx context.Context, feedID int64) error { _, err := q.db.ExecContext(ctx, markFeedArticlesUnread, feedID) return err } const updateArticle = `-- name: UpdateArticle :exec UPDATE articles SET title = ?, url = ? WHERE feed_id = ? AND guid = ? ` type UpdateArticleParams struct { Title string Url string FeedID int64 Guid string } func (q *Queries) UpdateArticle(ctx context.Context, arg UpdateArticleParams) error { _, err := q.db.ExecContext(ctx, updateArticle, arg.Title, arg.Url, arg.FeedID, arg.Guid, ) return err } const updateArticleReadStatus = `-- name: UpdateArticleReadStatus :exec UPDATE articles SET is_read = ? WHERE id = ? ` type UpdateArticleReadStatusParams struct { IsRead int64 ID int64 } func (q *Queries) UpdateArticleReadStatus(ctx context.Context, arg UpdateArticleReadStatusParams) error { _, err := q.db.ExecContext(ctx, updateArticleReadStatus, arg.IsRead, arg.ID) return err }