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