1// Code generated by sqlc. DO NOT EDIT.
2// versions:
3// sqlc v1.30.0
4// source: favorites.sql
5
6package sqlc
7
8import (
9 "context"
10 "database/sql"
11)
12
13const CreateFavorite = `-- name: CreateFavorite :one
14INSERT INTO favorites (url, title, favicon_url, position, created_at, updated_at)
15VALUES (?, ?, ?, COALESCE((SELECT MAX(position) + 1 FROM favorites), 0), CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
16RETURNING id, url, title, favicon_url, shortcut_key, position, created_at, updated_at
17`
18
19type CreateFavoriteParams struct {
20 Url string `json:"url"`
21 Title sql.NullString `json:"title"`
22 FaviconUrl sql.NullString `json:"favicon_url"`
23}
24
25type CreateFavoriteRow struct {
26 ID int64 `json:"id"`
27 Url string `json:"url"`
28 Title sql.NullString `json:"title"`
29 FaviconUrl sql.NullString `json:"favicon_url"`
30 ShortcutKey sql.NullInt64 `json:"shortcut_key"`
31 Position int64 `json:"position"`
32 CreatedAt sql.NullTime `json:"created_at"`
33 UpdatedAt sql.NullTime `json:"updated_at"`
34}
35
36func (q *Queries) CreateFavorite(ctx context.Context, arg CreateFavoriteParams) (CreateFavoriteRow, error) {
37 row := q.db.QueryRowContext(ctx, CreateFavorite, arg.Url, arg.Title, arg.FaviconUrl)
38 var i CreateFavoriteRow
39 err := row.Scan(
40 &i.ID,
41 &i.Url,
42 &i.Title,
43 &i.FaviconUrl,
44 &i.ShortcutKey,
45 &i.Position,
46 &i.CreatedAt,
47 &i.UpdatedAt,
48 )
49 return i, err
50}
51
52const DeleteFavorite = `-- name: DeleteFavorite :exec
53DELETE FROM favorites WHERE id = ?
54`
55
56func (q *Queries) DeleteFavorite(ctx context.Context, id int64) error {
57 _, err := q.db.ExecContext(ctx, DeleteFavorite, id)
58 return err
59}
60
61const GetAllFavorites = `-- name: GetAllFavorites :many
62SELECT id, url, title, favicon_url, shortcut_key, position, created_at, updated_at
63FROM favorites
64ORDER BY position ASC
65`
66
67type GetAllFavoritesRow struct {
68 ID int64 `json:"id"`
69 Url string `json:"url"`
70 Title sql.NullString `json:"title"`
71 FaviconUrl sql.NullString `json:"favicon_url"`
72 ShortcutKey sql.NullInt64 `json:"shortcut_key"`
73 Position int64 `json:"position"`
74 CreatedAt sql.NullTime `json:"created_at"`
75 UpdatedAt sql.NullTime `json:"updated_at"`
76}
77
78func (q *Queries) GetAllFavorites(ctx context.Context) ([]GetAllFavoritesRow, error) {
79 rows, err := q.db.QueryContext(ctx, GetAllFavorites)
80 if err != nil {
81 return nil, err
82 }
83 defer rows.Close()
84 items := []GetAllFavoritesRow{}
85 for rows.Next() {
86 var i GetAllFavoritesRow
87 if err := rows.Scan(
88 &i.ID,
89 &i.Url,
90 &i.Title,
91 &i.FaviconUrl,
92 &i.ShortcutKey,
93 &i.Position,
94 &i.CreatedAt,
95 &i.UpdatedAt,
96 ); err != nil {
97 return nil, err
98 }
99 items = append(items, i)
100 }
101 if err := rows.Close(); err != nil {
102 return nil, err
103 }
104 if err := rows.Err(); err != nil {
105 return nil, err
106 }
107 return items, nil
108}
109
110const GetFavoriteByID = `-- name: GetFavoriteByID :one
111SELECT id, url, title, favicon_url, shortcut_key, position, created_at, updated_at
112FROM favorites
113WHERE id = ? LIMIT 1
114`
115
116type GetFavoriteByIDRow struct {
117 ID int64 `json:"id"`
118 Url string `json:"url"`
119 Title sql.NullString `json:"title"`
120 FaviconUrl sql.NullString `json:"favicon_url"`
121 ShortcutKey sql.NullInt64 `json:"shortcut_key"`
122 Position int64 `json:"position"`
123 CreatedAt sql.NullTime `json:"created_at"`
124 UpdatedAt sql.NullTime `json:"updated_at"`
125}
126
127func (q *Queries) GetFavoriteByID(ctx context.Context, id int64) (GetFavoriteByIDRow, error) {
128 row := q.db.QueryRowContext(ctx, GetFavoriteByID, id)
129 var i GetFavoriteByIDRow
130 err := row.Scan(
131 &i.ID,
132 &i.Url,
133 &i.Title,
134 &i.FaviconUrl,
135 &i.ShortcutKey,
136 &i.Position,
137 &i.CreatedAt,
138 &i.UpdatedAt,
139 )
140 return i, err
141}
142
143const GetFavoriteByShortcut = `-- name: GetFavoriteByShortcut :one
144SELECT id, url, title, favicon_url, shortcut_key, position, created_at, updated_at
145FROM favorites
146WHERE shortcut_key = ? LIMIT 1
147`
148
149type GetFavoriteByShortcutRow struct {
150 ID int64 `json:"id"`
151 Url string `json:"url"`
152 Title sql.NullString `json:"title"`
153 FaviconUrl sql.NullString `json:"favicon_url"`
154 ShortcutKey sql.NullInt64 `json:"shortcut_key"`
155 Position int64 `json:"position"`
156 CreatedAt sql.NullTime `json:"created_at"`
157 UpdatedAt sql.NullTime `json:"updated_at"`
158}
159
160func (q *Queries) GetFavoriteByShortcut(ctx context.Context, shortcutKey sql.NullInt64) (GetFavoriteByShortcutRow, error) {
161 row := q.db.QueryRowContext(ctx, GetFavoriteByShortcut, shortcutKey)
162 var i GetFavoriteByShortcutRow
163 err := row.Scan(
164 &i.ID,
165 &i.Url,
166 &i.Title,
167 &i.FaviconUrl,
168 &i.ShortcutKey,
169 &i.Position,
170 &i.CreatedAt,
171 &i.UpdatedAt,
172 )
173 return i, err
174}
175
176const GetFavoriteByURL = `-- name: GetFavoriteByURL :one
177SELECT id, url, title, favicon_url, shortcut_key, position, created_at, updated_at
178FROM favorites
179WHERE url = ? LIMIT 1
180`
181
182type GetFavoriteByURLRow struct {
183 ID int64 `json:"id"`
184 Url string `json:"url"`
185 Title sql.NullString `json:"title"`
186 FaviconUrl sql.NullString `json:"favicon_url"`
187 ShortcutKey sql.NullInt64 `json:"shortcut_key"`
188 Position int64 `json:"position"`
189 CreatedAt sql.NullTime `json:"created_at"`
190 UpdatedAt sql.NullTime `json:"updated_at"`
191}
192
193func (q *Queries) GetFavoriteByURL(ctx context.Context, url string) (GetFavoriteByURLRow, error) {
194 row := q.db.QueryRowContext(ctx, GetFavoriteByURL, url)
195 var i GetFavoriteByURLRow
196 err := row.Scan(
197 &i.ID,
198 &i.Url,
199 &i.Title,
200 &i.FaviconUrl,
201 &i.ShortcutKey,
202 &i.Position,
203 &i.CreatedAt,
204 &i.UpdatedAt,
205 )
206 return i, err
207}
208
209const GetFavoritesByTag = `-- name: GetFavoritesByTag :many
210SELECT f.id, f.url, f.title, f.favicon_url, f.shortcut_key, f.position, f.created_at, f.updated_at
211FROM favorites f
212INNER JOIN favorite_tag_assignments fta ON f.id = fta.favorite_id
213WHERE fta.tag_id = ?
214ORDER BY f.position ASC
215`
216
217type GetFavoritesByTagRow struct {
218 ID int64 `json:"id"`
219 Url string `json:"url"`
220 Title sql.NullString `json:"title"`
221 FaviconUrl sql.NullString `json:"favicon_url"`
222 ShortcutKey sql.NullInt64 `json:"shortcut_key"`
223 Position int64 `json:"position"`
224 CreatedAt sql.NullTime `json:"created_at"`
225 UpdatedAt sql.NullTime `json:"updated_at"`
226}
227
228func (q *Queries) GetFavoritesByTag(ctx context.Context, tagID int64) ([]GetFavoritesByTagRow, error) {
229 rows, err := q.db.QueryContext(ctx, GetFavoritesByTag, tagID)
230 if err != nil {
231 return nil, err
232 }
233 defer rows.Close()
234 items := []GetFavoritesByTagRow{}
235 for rows.Next() {
236 var i GetFavoritesByTagRow
237 if err := rows.Scan(
238 &i.ID,
239 &i.Url,
240 &i.Title,
241 &i.FaviconUrl,
242 &i.ShortcutKey,
243 &i.Position,
244 &i.CreatedAt,
245 &i.UpdatedAt,
246 ); err != nil {
247 return nil, err
248 }
249 items = append(items, i)
250 }
251 if err := rows.Close(); err != nil {
252 return nil, err
253 }
254 if err := rows.Err(); err != nil {
255 return nil, err
256 }
257 return items, nil
258}
259
260const SetFavoriteShortcut = `-- name: SetFavoriteShortcut :exec
261UPDATE favorites SET shortcut_key = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?
262`
263
264type SetFavoriteShortcutParams struct {
265 ShortcutKey sql.NullInt64 `json:"shortcut_key"`
266 ID int64 `json:"id"`
267}
268
269func (q *Queries) SetFavoriteShortcut(ctx context.Context, arg SetFavoriteShortcutParams) error {
270 _, err := q.db.ExecContext(ctx, SetFavoriteShortcut, arg.ShortcutKey, arg.ID)
271 return err
272}
273
274const UpdateFavorite = `-- name: UpdateFavorite :exec
275UPDATE favorites
276SET title = ?, favicon_url = ?, shortcut_key = ?, updated_at = CURRENT_TIMESTAMP
277WHERE id = ?
278`
279
280type UpdateFavoriteParams struct {
281 Title sql.NullString `json:"title"`
282 FaviconUrl sql.NullString `json:"favicon_url"`
283 ShortcutKey sql.NullInt64 `json:"shortcut_key"`
284 ID int64 `json:"id"`
285}
286
287func (q *Queries) UpdateFavorite(ctx context.Context, arg UpdateFavoriteParams) error {
288 _, err := q.db.ExecContext(ctx, UpdateFavorite,
289 arg.Title,
290 arg.FaviconUrl,
291 arg.ShortcutKey,
292 arg.ID,
293 )
294 return err
295}
296
297const UpdateFavoritePosition = `-- name: UpdateFavoritePosition :exec
298UPDATE favorites SET position = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?
299`
300
301type UpdateFavoritePositionParams struct {
302 Position int64 `json:"position"`
303 ID int64 `json:"id"`
304}
305
306func (q *Queries) UpdateFavoritePosition(ctx context.Context, arg UpdateFavoritePositionParams) error {
307 _, err := q.db.ExecContext(ctx, UpdateFavoritePosition, arg.Position, arg.ID)
308 return err
309}