1// Code generated by sqlc. DO NOT EDIT.
2// versions:
3// sqlc v1.30.0
4// source: favorites.sql
5
6package db
7
8import (
9 "context"
10 "database/sql"
11)
12
13const CreateFavorite = `-- name: CreateFavorite :exec
14INSERT INTO favorites (url, title, favicon_url, position, created_at, updated_at)
15VALUES (
16 ?,
17 ?,
18 ?,
19 COALESCE((SELECT MAX(position) + 1 FROM favorites), 0),
20 CURRENT_TIMESTAMP,
21 CURRENT_TIMESTAMP
22)
23`
24
25// Insert a new favorite with auto-incremented position
26func (q *Queries) CreateFavorite(ctx context.Context, url string, title sql.NullString, faviconUrl sql.NullString) error {
27 _, err := q.db.ExecContext(ctx, CreateFavorite, url, title, faviconUrl)
28 return err
29}
30
31const DeleteFavorite = `-- name: DeleteFavorite :exec
32DELETE FROM favorites
33WHERE url = ?
34`
35
36// Delete a favorite by URL
37func (q *Queries) DeleteFavorite(ctx context.Context, url string) error {
38 _, err := q.db.ExecContext(ctx, DeleteFavorite, url)
39 return err
40}
41
42const GetAllFavorites = `-- name: GetAllFavorites :many
43SELECT id, url, title, favicon_url, position, created_at, updated_at
44FROM favorites
45ORDER BY position ASC
46`
47
48// Get all favorites ordered by position
49func (q *Queries) GetAllFavorites(ctx context.Context) ([]Favorite, error) {
50 rows, err := q.db.QueryContext(ctx, GetAllFavorites)
51 if err != nil {
52 return nil, err
53 }
54 defer rows.Close()
55 items := []Favorite{}
56 for rows.Next() {
57 var i Favorite
58 if err := rows.Scan(
59 &i.ID,
60 &i.Url,
61 &i.Title,
62 &i.FaviconUrl,
63 &i.Position,
64 &i.CreatedAt,
65 &i.UpdatedAt,
66 ); err != nil {
67 return nil, err
68 }
69 items = append(items, i)
70 }
71 if err := rows.Close(); err != nil {
72 return nil, err
73 }
74 if err := rows.Err(); err != nil {
75 return nil, err
76 }
77 return items, nil
78}
79
80const GetFavoriteByURL = `-- name: GetFavoriteByURL :one
81SELECT id, url, title, favicon_url, position, created_at, updated_at
82FROM favorites
83WHERE url = ?
84LIMIT 1
85`
86
87// Get a specific favorite by URL
88func (q *Queries) GetFavoriteByURL(ctx context.Context, url string) (Favorite, error) {
89 row := q.db.QueryRowContext(ctx, GetFavoriteByURL, url)
90 var i Favorite
91 err := row.Scan(
92 &i.ID,
93 &i.Url,
94 &i.Title,
95 &i.FaviconUrl,
96 &i.Position,
97 &i.CreatedAt,
98 &i.UpdatedAt,
99 )
100 return i, err
101}
102
103const GetFavoriteCount = `-- name: GetFavoriteCount :one
104SELECT COUNT(*) as count
105FROM favorites
106`
107
108// Get total count of favorites
109func (q *Queries) GetFavoriteCount(ctx context.Context) (int64, error) {
110 row := q.db.QueryRowContext(ctx, GetFavoriteCount)
111 var count int64
112 err := row.Scan(&count)
113 return count, err
114}
115
116const IsFavorite = `-- name: IsFavorite :one
117SELECT COUNT(*) as count
118FROM favorites
119WHERE url = ?
120LIMIT 1
121`
122
123// Check if a URL is favorited
124func (q *Queries) IsFavorite(ctx context.Context, url string) (int64, error) {
125 row := q.db.QueryRowContext(ctx, IsFavorite, url)
126 var count int64
127 err := row.Scan(&count)
128 return count, err
129}
130
131const UpdateFavorite = `-- name: UpdateFavorite :exec
132UPDATE favorites
133SET
134 title = ?,
135 favicon_url = ?,
136 updated_at = CURRENT_TIMESTAMP
137WHERE url = ?
138`
139
140// Update favorite metadata (title, favicon)
141func (q *Queries) UpdateFavorite(ctx context.Context, title sql.NullString, faviconUrl sql.NullString, url string) error {
142 _, err := q.db.ExecContext(ctx, UpdateFavorite, title, faviconUrl, url)
143 return err
144}
145
146const UpdateFavoritePosition = `-- name: UpdateFavoritePosition :exec
147UPDATE favorites
148SET
149 position = ?,
150 updated_at = CURRENT_TIMESTAMP
151WHERE url = ?
152`
153
154// Update the position of a favorite
155func (q *Queries) UpdateFavoritePosition(ctx context.Context, position int64, url string) error {
156 _, err := q.db.ExecContext(ctx, UpdateFavoritePosition, position, url)
157 return err
158}