aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/db/feeds.sql.go
blob: 29b26caeb16cfcb708c336bb70ffcb65e8fa5b5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.29.0
// source: feeds.sql

package db

import (
	"context"
)

const createFeed = `-- name: CreateFeed :one
INSERT INTO feeds (url, title, fetched_at)
VALUES (?, ?, ?)
RETURNING id, url, title, fetched_at, is_subscribed
`

type CreateFeedParams struct {
	Url       string
	Title     string
	FetchedAt string
}

func (q *Queries) CreateFeed(ctx context.Context, arg CreateFeedParams) (Feed, error) {
	row := q.db.QueryRowContext(ctx, createFeed, arg.Url, arg.Title, arg.FetchedAt)
	var i Feed
	err := row.Scan(
		&i.ID,
		&i.Url,
		&i.Title,
		&i.FetchedAt,
		&i.IsSubscribed,
	)
	return i, err
}

const deleteFeed = `-- name: DeleteFeed :exec
DELETE FROM feeds
WHERE id = ?
`

func (q *Queries) DeleteFeed(ctx context.Context, id int64) error {
	_, err := q.db.ExecContext(ctx, deleteFeed, id)
	return err
}

const getFeed = `-- name: GetFeed :one
SELECT id, url, title, fetched_at, is_subscribed
FROM feeds
WHERE id = ?
`

func (q *Queries) GetFeed(ctx context.Context, id int64) (Feed, error) {
	row := q.db.QueryRowContext(ctx, getFeed, id)
	var i Feed
	err := row.Scan(
		&i.ID,
		&i.Url,
		&i.Title,
		&i.FetchedAt,
		&i.IsSubscribed,
	)
	return i, err
}

const getFeedByURL = `-- name: GetFeedByURL :one
SELECT id, url, title, fetched_at, is_subscribed
FROM feeds
WHERE url = ?
`

func (q *Queries) GetFeedByURL(ctx context.Context, url string) (Feed, error) {
	row := q.db.QueryRowContext(ctx, getFeedByURL, url)
	var i Feed
	err := row.Scan(
		&i.ID,
		&i.Url,
		&i.Title,
		&i.FetchedAt,
		&i.IsSubscribed,
	)
	return i, err
}

const getFeeds = `-- name: GetFeeds :many
SELECT id, url, title, fetched_at, is_subscribed
FROM feeds
WHERE is_subscribed = 1
ORDER BY id
`

func (q *Queries) GetFeeds(ctx context.Context) ([]Feed, error) {
	rows, err := q.db.QueryContext(ctx, getFeeds)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Feed{}
	for rows.Next() {
		var i Feed
		if err := rows.Scan(
			&i.ID,
			&i.Url,
			&i.Title,
			&i.FetchedAt,
			&i.IsSubscribed,
		); 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 getFeedsToFetch = `-- name: GetFeedsToFetch :many
SELECT id, url, fetched_at
FROM feeds
WHERE is_subscribed = 1
`

type GetFeedsToFetchRow struct {
	ID        int64
	Url       string
	FetchedAt string
}

func (q *Queries) GetFeedsToFetch(ctx context.Context) ([]GetFeedsToFetchRow, error) {
	rows, err := q.db.QueryContext(ctx, getFeedsToFetch)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []GetFeedsToFetchRow{}
	for rows.Next() {
		var i GetFeedsToFetchRow
		if err := rows.Scan(&i.ID, &i.Url, &i.FetchedAt); 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 unsubscribeFeed = `-- name: UnsubscribeFeed :exec
UPDATE feeds
SET is_subscribed = 0
WHERE id = ?
`

func (q *Queries) UnsubscribeFeed(ctx context.Context, id int64) error {
	_, err := q.db.ExecContext(ctx, unsubscribeFeed, id)
	return err
}

const updateFeedMetadata = `-- name: UpdateFeedMetadata :exec
UPDATE feeds
SET title = ?, fetched_at = ?
WHERE id = ?
`

type UpdateFeedMetadataParams struct {
	Title     string
	FetchedAt string
	ID        int64
}

func (q *Queries) UpdateFeedMetadata(ctx context.Context, arg UpdateFeedMetadataParams) error {
	_, err := q.db.ExecContext(ctx, updateFeedMetadata, arg.Title, arg.FetchedAt, arg.ID)
	return err
}