-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathqueries.sql_sqlc.go
More file actions
263 lines (228 loc) · 6.11 KB
/
queries.sql_sqlc.go
File metadata and controls
263 lines (228 loc) · 6.11 KB
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: queries.sql
package main
import (
"context"
"database/sql"
)
const countInbox = `-- name: CountInbox :one
SELECT count(*) FROM inbox
`
func (q *Queries) CountInbox(ctx context.Context) (int64, error) {
row := q.db.QueryRowContext(ctx, countInbox)
var count int64
err := row.Scan(&count)
return count, err
}
const countOutbox = `-- name: CountOutbox :one
SELECT count(*) FROM sent_messages WHERE conversation_id = ?
`
func (q *Queries) CountOutbox(ctx context.Context, conversationID string) (int64, error) {
row := q.db.QueryRowContext(ctx, countOutbox, conversationID)
var count int64
err := row.Scan(&count)
return count, err
}
const deleteInboxItem = `-- name: DeleteInboxItem :exec
DELETE FROM inbox WHERE id = ?
`
func (q *Queries) DeleteInboxItem(ctx context.Context, id int64) error {
_, err := q.db.ExecContext(ctx, deleteInboxItem, id)
return err
}
const deleteOldestOutbox = `-- name: DeleteOldestOutbox :exec
DELETE FROM sent_messages
WHERE rowid IN (
SELECT sm.rowid FROM sent_messages sm
WHERE sm.conversation_id = ?
ORDER BY sm.rowid ASC
LIMIT ?
)
`
type DeleteOldestOutboxParams struct {
ConversationID string
Limit int64
}
func (q *Queries) DeleteOldestOutbox(ctx context.Context, arg DeleteOldestOutboxParams) error {
_, err := q.db.ExecContext(ctx, deleteOldestOutbox, arg.ConversationID, arg.Limit)
return err
}
const deleteStaleItems = `-- name: DeleteStaleItems :exec
DELETE FROM inbox WHERE source IN ('heartbeat', 'compact')
`
func (q *Queries) DeleteStaleItems(ctx context.Context) error {
_, err := q.db.ExecContext(ctx, deleteStaleItems)
return err
}
const dequeueInbox = `-- name: DequeueInbox :one
DELETE FROM inbox
WHERE id = (
SELECT id FROM inbox
ORDER BY priority ASC, id ASC
LIMIT 1
)
RETURNING id, priority, source, content, reply_to, created_at
`
func (q *Queries) DequeueInbox(ctx context.Context) (Inbox, error) {
row := q.db.QueryRowContext(ctx, dequeueInbox)
var i Inbox
err := row.Scan(
&i.ID,
&i.Priority,
&i.Source,
&i.Content,
&i.ReplyTo,
&i.CreatedAt,
)
return i, err
}
const dequeueUserItems = `-- name: DequeueUserItems :many
DELETE FROM inbox
WHERE source = 'user'
RETURNING id, priority, source, content, reply_to, created_at
`
func (q *Queries) DequeueUserItems(ctx context.Context) ([]Inbox, error) {
rows, err := q.db.QueryContext(ctx, dequeueUserItems)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Inbox
for rows.Next() {
var i Inbox
if err := rows.Scan(
&i.ID,
&i.Priority,
&i.Source,
&i.Content,
&i.ReplyTo,
&i.CreatedAt,
); 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 dueReminders = `-- name: DueReminders :many
DELETE FROM reminders
WHERE datetime(fire_at) <= datetime(?)
RETURNING id, fire_at, prompt
`
// datetime() normalizes ISO 8601 variants (Z vs +00:00, T vs space) so
// lexicographic comparison doesn't break on agent-formatted timestamps.
func (q *Queries) DueReminders(ctx context.Context, datetime interface{}) ([]Reminders, error) {
rows, err := q.db.QueryContext(ctx, dueReminders, datetime)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Reminders
for rows.Next() {
var i Reminders
if err := rows.Scan(&i.ID, &i.FireAt, &i.Prompt); 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 enqueueHeartbeatIfEmpty = `-- name: EnqueueHeartbeatIfEmpty :execresult
INSERT INTO inbox (priority, source, content, reply_to)
SELECT ?, 'heartbeat', '', ''
WHERE NOT EXISTS (SELECT 1 FROM inbox WHERE source = 'heartbeat')
`
func (q *Queries) EnqueueHeartbeatIfEmpty(ctx context.Context, priority int64) (sql.Result, error) {
return q.db.ExecContext(ctx, enqueueHeartbeatIfEmpty, priority)
}
const enqueueInbox = `-- name: EnqueueInbox :exec
INSERT INTO inbox (priority, source, content, reply_to)
VALUES (?, ?, ?, ?)
`
type EnqueueInboxParams struct {
Priority int64
Source string
Content string
ReplyTo string
}
func (q *Queries) EnqueueInbox(ctx context.Context, arg EnqueueInboxParams) error {
_, err := q.db.ExecContext(ctx, enqueueInbox,
arg.Priority,
arg.Source,
arg.Content,
arg.ReplyTo,
)
return err
}
const getOutbox = `-- name: GetOutbox :one
SELECT text FROM sent_messages
WHERE conversation_id = ? AND message_id = ?
`
type GetOutboxParams struct {
ConversationID string
MessageID string
}
func (q *Queries) GetOutbox(ctx context.Context, arg GetOutboxParams) (string, error) {
row := q.db.QueryRowContext(ctx, getOutbox, arg.ConversationID, arg.MessageID)
var text string
err := row.Scan(&text)
return text, err
}
const insertReminder = `-- name: InsertReminder :exec
INSERT INTO reminders (fire_at, prompt) VALUES (?, ?)
`
type InsertReminderParams struct {
FireAt string
Prompt string
}
func (q *Queries) InsertReminder(ctx context.Context, arg InsertReminderParams) error {
_, err := q.db.ExecContext(ctx, insertReminder, arg.FireAt, arg.Prompt)
return err
}
const peekInbox = `-- name: PeekInbox :one
SELECT id, priority, source, content, reply_to, created_at
FROM inbox
ORDER BY priority ASC, id ASC
LIMIT 1
`
func (q *Queries) PeekInbox(ctx context.Context) (Inbox, error) {
row := q.db.QueryRowContext(ctx, peekInbox)
var i Inbox
err := row.Scan(
&i.ID,
&i.Priority,
&i.Source,
&i.Content,
&i.ReplyTo,
&i.CreatedAt,
)
return i, err
}
const upsertOutbox = `-- name: UpsertOutbox :exec
INSERT INTO sent_messages (conversation_id, message_id, text)
VALUES (?, ?, ?)
ON CONFLICT(conversation_id, message_id) DO UPDATE SET text = excluded.text
`
type UpsertOutboxParams struct {
ConversationID string
MessageID string
Text string
}
func (q *Queries) UpsertOutbox(ctx context.Context, arg UpsertOutboxParams) error {
_, err := q.db.ExecContext(ctx, upsertOutbox, arg.ConversationID, arg.MessageID, arg.Text)
return err
}