diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-07-12 17:11:13 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-07-12 17:52:54 +0900 |
| commit | fbe4bff7e8b6a5239c490601436fb3638dc8e13b (patch) | |
| tree | b011c43d20ebfc4566cdbe95ed878c9644797e37 /backend/db/articles.sql.go | |
| parent | db4f7f4ee12ab52ff249b29496a9f0997e3dbbf5 (diff) | |
| download | feedaka-fbe4bff7e8b6a5239c490601436fb3638dc8e13b.tar.gz feedaka-fbe4bff7e8b6a5239c490601436fb3638dc8e13b.tar.zst feedaka-fbe4bff7e8b6a5239c490601436fb3638dc8e13b.zip | |
feat(backend): introduce sqlc
Diffstat (limited to 'backend/db/articles.sql.go')
| -rw-r--r-- | backend/db/articles.sql.go | 350 |
1 files changed, 350 insertions, 0 deletions
diff --git a/backend/db/articles.sql.go b/backend/db/articles.sql.go new file mode 100644 index 0000000..9e60cb4 --- /dev/null +++ b/backend/db/articles.sql.go @@ -0,0 +1,350 @@ +// 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 +FROM articles AS a +INNER JOIN feeds AS f ON a.feed_id = f.id +WHERE a.id = ? +` + +type GetArticleRow struct { + ID int64 + FeedID int64 + Guid string + Title string + Url string + IsRead int64 + FeedID2 int64 + FeedUrl string + FeedTitle string +} + +func (q *Queries) GetArticle(ctx context.Context, id int64) (GetArticleRow, error) { + row := q.db.QueryRowContext(ctx, getArticle, id) + var i GetArticleRow + err := row.Scan( + &i.ID, + &i.FeedID, + &i.Guid, + &i.Title, + &i.Url, + &i.IsRead, + &i.FeedID2, + &i.FeedUrl, + &i.FeedTitle, + ) + 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 +FROM articles AS a +INNER JOIN feeds AS f ON a.feed_id = f.id +WHERE a.is_read = 1 +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 +} + +func (q *Queries) GetReadArticles(ctx context.Context) ([]GetReadArticlesRow, error) { + rows, err := q.db.QueryContext(ctx, getReadArticles) + 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, + ); 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 +FROM articles AS a +INNER JOIN feeds AS f ON a.feed_id = f.id +WHERE a.is_read = 0 +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 +} + +func (q *Queries) GetUnreadArticles(ctx context.Context) ([]GetUnreadArticlesRow, error) { + rows, err := q.db.QueryContext(ctx, getUnreadArticles) + 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, + ); 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 +} |
