1// Code generated by sqlc. DO NOT EDIT.
2// versions:
3// sqlc v1.30.0
4// source: history.sql
5
6package db
7
8import (
9 "context"
10 "database/sql"
11)
12
13const AddOrUpdateHistory = `-- name: AddOrUpdateHistory :exec
14INSERT INTO history (url, title)
15VALUES (?, ?)
16ON CONFLICT(url)
17DO UPDATE SET
18 visit_count = visit_count + 1,
19 last_visited = CURRENT_TIMESTAMP,
20 title = EXCLUDED.title
21`
22
23func (q *Queries) AddOrUpdateHistory(ctx context.Context, url string, title sql.NullString) error {
24 _, err := q.db.ExecContext(ctx, AddOrUpdateHistory, url, title)
25 return err
26}
27
28const DeleteAllHistory = `-- name: DeleteAllHistory :exec
29DELETE FROM history
30`
31
32func (q *Queries) DeleteAllHistory(ctx context.Context) error {
33 _, err := q.db.ExecContext(ctx, DeleteAllHistory)
34 return err
35}
36
37const DeleteHistory = `-- name: DeleteHistory :exec
38DELETE FROM history
39WHERE id = ?
40`
41
42func (q *Queries) DeleteHistory(ctx context.Context, id int64) error {
43 _, err := q.db.ExecContext(ctx, DeleteHistory, id)
44 return err
45}
46
47const GetHistory = `-- name: GetHistory :many
48SELECT id, url, title, visit_count, last_visited, created_at, favicon_url
49FROM history
50ORDER BY last_visited DESC
51LIMIT ?
52`
53
54func (q *Queries) GetHistory(ctx context.Context, limit int64) ([]History, error) {
55 rows, err := q.db.QueryContext(ctx, GetHistory, limit)
56 if err != nil {
57 return nil, err
58 }
59 defer rows.Close()
60 items := []History{}
61 for rows.Next() {
62 var i History
63 if err := rows.Scan(
64 &i.ID,
65 &i.Url,
66 &i.Title,
67 &i.VisitCount,
68 &i.LastVisited,
69 &i.CreatedAt,
70 &i.FaviconUrl,
71 ); err != nil {
72 return nil, err
73 }
74 items = append(items, i)
75 }
76 if err := rows.Close(); err != nil {
77 return nil, err
78 }
79 if err := rows.Err(); err != nil {
80 return nil, err
81 }
82 return items, nil
83}
84
85const GetHistoryEntry = `-- name: GetHistoryEntry :one
86SELECT id, url, title, visit_count, last_visited, created_at, favicon_url
87FROM history
88WHERE url = ?
89LIMIT 1
90`
91
92func (q *Queries) GetHistoryEntry(ctx context.Context, url string) (History, error) {
93 row := q.db.QueryRowContext(ctx, GetHistoryEntry, url)
94 var i History
95 err := row.Scan(
96 &i.ID,
97 &i.Url,
98 &i.Title,
99 &i.VisitCount,
100 &i.LastVisited,
101 &i.CreatedAt,
102 &i.FaviconUrl,
103 )
104 return i, err
105}
106
107const GetHistoryWithOffset = `-- name: GetHistoryWithOffset :many
108SELECT id, url, title, visit_count, last_visited, created_at, favicon_url
109FROM history
110ORDER BY last_visited DESC
111LIMIT ? OFFSET ?
112`
113
114func (q *Queries) GetHistoryWithOffset(ctx context.Context, limit int64, offset int64) ([]History, error) {
115 rows, err := q.db.QueryContext(ctx, GetHistoryWithOffset, limit, offset)
116 if err != nil {
117 return nil, err
118 }
119 defer rows.Close()
120 items := []History{}
121 for rows.Next() {
122 var i History
123 if err := rows.Scan(
124 &i.ID,
125 &i.Url,
126 &i.Title,
127 &i.VisitCount,
128 &i.LastVisited,
129 &i.CreatedAt,
130 &i.FaviconUrl,
131 ); err != nil {
132 return nil, err
133 }
134 items = append(items, i)
135 }
136 if err := rows.Close(); err != nil {
137 return nil, err
138 }
139 if err := rows.Err(); err != nil {
140 return nil, err
141 }
142 return items, nil
143}
144
145const GetMostVisited = `-- name: GetMostVisited :many
146SELECT id, url, title, visit_count, last_visited, created_at, favicon_url
147FROM history
148ORDER BY visit_count DESC, last_visited DESC
149LIMIT ?
150`
151
152func (q *Queries) GetMostVisited(ctx context.Context, limit int64) ([]History, error) {
153 rows, err := q.db.QueryContext(ctx, GetMostVisited, limit)
154 if err != nil {
155 return nil, err
156 }
157 defer rows.Close()
158 items := []History{}
159 for rows.Next() {
160 var i History
161 if err := rows.Scan(
162 &i.ID,
163 &i.Url,
164 &i.Title,
165 &i.VisitCount,
166 &i.LastVisited,
167 &i.CreatedAt,
168 &i.FaviconUrl,
169 ); err != nil {
170 return nil, err
171 }
172 items = append(items, i)
173 }
174 if err := rows.Close(); err != nil {
175 return nil, err
176 }
177 if err := rows.Err(); err != nil {
178 return nil, err
179 }
180 return items, nil
181}
182
183const SearchHistory = `-- name: SearchHistory :many
184SELECT id, url, title, visit_count, last_visited, created_at, favicon_url
185FROM history
186WHERE url LIKE '%' || ? || '%' OR title LIKE '%' || ? || '%'
187ORDER BY visit_count DESC, last_visited DESC
188LIMIT ?
189`
190
191func (q *Queries) SearchHistory(ctx context.Context, column1 sql.NullString, column2 sql.NullString, limit int64) ([]History, error) {
192 rows, err := q.db.QueryContext(ctx, SearchHistory, column1, column2, limit)
193 if err != nil {
194 return nil, err
195 }
196 defer rows.Close()
197 items := []History{}
198 for rows.Next() {
199 var i History
200 if err := rows.Scan(
201 &i.ID,
202 &i.Url,
203 &i.Title,
204 &i.VisitCount,
205 &i.LastVisited,
206 &i.CreatedAt,
207 &i.FaviconUrl,
208 ); err != nil {
209 return nil, err
210 }
211 items = append(items, i)
212 }
213 if err := rows.Close(); err != nil {
214 return nil, err
215 }
216 if err := rows.Err(); err != nil {
217 return nil, err
218 }
219 return items, nil
220}
221
222const UpdateHistoryFavicon = `-- name: UpdateHistoryFavicon :exec
223UPDATE history
224SET favicon_url = ?
225WHERE url = ?
226`
227
228func (q *Queries) UpdateHistoryFavicon(ctx context.Context, faviconUrl sql.NullString, url string) error {
229 _, err := q.db.ExecContext(ctx, UpdateHistoryFavicon, faviconUrl, url)
230 return err
231}