1// Code generated by sqlc. DO NOT EDIT.
2// versions:
3// sqlc v1.30.0
4// source: conversations.sql
5
6package generated
7
8import (
9 "context"
10)
11
12const archiveConversation = `-- name: ArchiveConversation :one
13UPDATE conversations
14SET archived = TRUE, updated_at = CURRENT_TIMESTAMP
15WHERE conversation_id = ?
16RETURNING conversation_id, slug, user_initiated, created_at, updated_at, cwd, archived, parent_conversation_id, model
17`
18
19func (q *Queries) ArchiveConversation(ctx context.Context, conversationID string) (Conversation, error) {
20 row := q.db.QueryRowContext(ctx, archiveConversation, conversationID)
21 var i Conversation
22 err := row.Scan(
23 &i.ConversationID,
24 &i.Slug,
25 &i.UserInitiated,
26 &i.CreatedAt,
27 &i.UpdatedAt,
28 &i.Cwd,
29 &i.Archived,
30 &i.ParentConversationID,
31 &i.Model,
32 )
33 return i, err
34}
35
36const countArchivedConversations = `-- name: CountArchivedConversations :one
37SELECT COUNT(*) FROM conversations WHERE archived = TRUE
38`
39
40func (q *Queries) CountArchivedConversations(ctx context.Context) (int64, error) {
41 row := q.db.QueryRowContext(ctx, countArchivedConversations)
42 var count int64
43 err := row.Scan(&count)
44 return count, err
45}
46
47const countConversations = `-- name: CountConversations :one
48SELECT COUNT(*) FROM conversations WHERE archived = FALSE AND parent_conversation_id IS NULL
49`
50
51func (q *Queries) CountConversations(ctx context.Context) (int64, error) {
52 row := q.db.QueryRowContext(ctx, countConversations)
53 var count int64
54 err := row.Scan(&count)
55 return count, err
56}
57
58const createConversation = `-- name: CreateConversation :one
59INSERT INTO conversations (conversation_id, slug, user_initiated, cwd, model)
60VALUES (?, ?, ?, ?, ?)
61RETURNING conversation_id, slug, user_initiated, created_at, updated_at, cwd, archived, parent_conversation_id, model
62`
63
64type CreateConversationParams struct {
65 ConversationID string `json:"conversation_id"`
66 Slug *string `json:"slug"`
67 UserInitiated bool `json:"user_initiated"`
68 Cwd *string `json:"cwd"`
69 Model *string `json:"model"`
70}
71
72func (q *Queries) CreateConversation(ctx context.Context, arg CreateConversationParams) (Conversation, error) {
73 row := q.db.QueryRowContext(ctx, createConversation,
74 arg.ConversationID,
75 arg.Slug,
76 arg.UserInitiated,
77 arg.Cwd,
78 arg.Model,
79 )
80 var i Conversation
81 err := row.Scan(
82 &i.ConversationID,
83 &i.Slug,
84 &i.UserInitiated,
85 &i.CreatedAt,
86 &i.UpdatedAt,
87 &i.Cwd,
88 &i.Archived,
89 &i.ParentConversationID,
90 &i.Model,
91 )
92 return i, err
93}
94
95const createSubagentConversation = `-- name: CreateSubagentConversation :one
96INSERT INTO conversations (conversation_id, slug, user_initiated, cwd, parent_conversation_id)
97VALUES (?, ?, FALSE, ?, ?)
98RETURNING conversation_id, slug, user_initiated, created_at, updated_at, cwd, archived, parent_conversation_id, model
99`
100
101type CreateSubagentConversationParams struct {
102 ConversationID string `json:"conversation_id"`
103 Slug *string `json:"slug"`
104 Cwd *string `json:"cwd"`
105 ParentConversationID *string `json:"parent_conversation_id"`
106}
107
108func (q *Queries) CreateSubagentConversation(ctx context.Context, arg CreateSubagentConversationParams) (Conversation, error) {
109 row := q.db.QueryRowContext(ctx, createSubagentConversation,
110 arg.ConversationID,
111 arg.Slug,
112 arg.Cwd,
113 arg.ParentConversationID,
114 )
115 var i Conversation
116 err := row.Scan(
117 &i.ConversationID,
118 &i.Slug,
119 &i.UserInitiated,
120 &i.CreatedAt,
121 &i.UpdatedAt,
122 &i.Cwd,
123 &i.Archived,
124 &i.ParentConversationID,
125 &i.Model,
126 )
127 return i, err
128}
129
130const deleteConversation = `-- name: DeleteConversation :exec
131DELETE FROM conversations
132WHERE conversation_id = ?
133`
134
135func (q *Queries) DeleteConversation(ctx context.Context, conversationID string) error {
136 _, err := q.db.ExecContext(ctx, deleteConversation, conversationID)
137 return err
138}
139
140const getConversation = `-- name: GetConversation :one
141SELECT conversation_id, slug, user_initiated, created_at, updated_at, cwd, archived, parent_conversation_id, model FROM conversations
142WHERE conversation_id = ?
143`
144
145func (q *Queries) GetConversation(ctx context.Context, conversationID string) (Conversation, error) {
146 row := q.db.QueryRowContext(ctx, getConversation, conversationID)
147 var i Conversation
148 err := row.Scan(
149 &i.ConversationID,
150 &i.Slug,
151 &i.UserInitiated,
152 &i.CreatedAt,
153 &i.UpdatedAt,
154 &i.Cwd,
155 &i.Archived,
156 &i.ParentConversationID,
157 &i.Model,
158 )
159 return i, err
160}
161
162const getConversationBySlug = `-- name: GetConversationBySlug :one
163SELECT conversation_id, slug, user_initiated, created_at, updated_at, cwd, archived, parent_conversation_id, model FROM conversations
164WHERE slug = ?
165`
166
167func (q *Queries) GetConversationBySlug(ctx context.Context, slug *string) (Conversation, error) {
168 row := q.db.QueryRowContext(ctx, getConversationBySlug, slug)
169 var i Conversation
170 err := row.Scan(
171 &i.ConversationID,
172 &i.Slug,
173 &i.UserInitiated,
174 &i.CreatedAt,
175 &i.UpdatedAt,
176 &i.Cwd,
177 &i.Archived,
178 &i.ParentConversationID,
179 &i.Model,
180 )
181 return i, err
182}
183
184const getConversationBySlugAndParent = `-- name: GetConversationBySlugAndParent :one
185SELECT conversation_id, slug, user_initiated, created_at, updated_at, cwd, archived, parent_conversation_id, model FROM conversations
186WHERE slug = ? AND parent_conversation_id = ?
187`
188
189type GetConversationBySlugAndParentParams struct {
190 Slug *string `json:"slug"`
191 ParentConversationID *string `json:"parent_conversation_id"`
192}
193
194func (q *Queries) GetConversationBySlugAndParent(ctx context.Context, arg GetConversationBySlugAndParentParams) (Conversation, error) {
195 row := q.db.QueryRowContext(ctx, getConversationBySlugAndParent, arg.Slug, arg.ParentConversationID)
196 var i Conversation
197 err := row.Scan(
198 &i.ConversationID,
199 &i.Slug,
200 &i.UserInitiated,
201 &i.CreatedAt,
202 &i.UpdatedAt,
203 &i.Cwd,
204 &i.Archived,
205 &i.ParentConversationID,
206 &i.Model,
207 )
208 return i, err
209}
210
211const getSubagents = `-- name: GetSubagents :many
212SELECT conversation_id, slug, user_initiated, created_at, updated_at, cwd, archived, parent_conversation_id, model FROM conversations
213WHERE parent_conversation_id = ?
214ORDER BY created_at ASC
215`
216
217func (q *Queries) GetSubagents(ctx context.Context, parentConversationID *string) ([]Conversation, error) {
218 rows, err := q.db.QueryContext(ctx, getSubagents, parentConversationID)
219 if err != nil {
220 return nil, err
221 }
222 defer rows.Close()
223 items := []Conversation{}
224 for rows.Next() {
225 var i Conversation
226 if err := rows.Scan(
227 &i.ConversationID,
228 &i.Slug,
229 &i.UserInitiated,
230 &i.CreatedAt,
231 &i.UpdatedAt,
232 &i.Cwd,
233 &i.Archived,
234 &i.ParentConversationID,
235 &i.Model,
236 ); err != nil {
237 return nil, err
238 }
239 items = append(items, i)
240 }
241 if err := rows.Close(); err != nil {
242 return nil, err
243 }
244 if err := rows.Err(); err != nil {
245 return nil, err
246 }
247 return items, nil
248}
249
250const listArchivedConversations = `-- name: ListArchivedConversations :many
251SELECT conversation_id, slug, user_initiated, created_at, updated_at, cwd, archived, parent_conversation_id, model FROM conversations
252WHERE archived = TRUE
253ORDER BY updated_at DESC
254LIMIT ? OFFSET ?
255`
256
257type ListArchivedConversationsParams struct {
258 Limit int64 `json:"limit"`
259 Offset int64 `json:"offset"`
260}
261
262func (q *Queries) ListArchivedConversations(ctx context.Context, arg ListArchivedConversationsParams) ([]Conversation, error) {
263 rows, err := q.db.QueryContext(ctx, listArchivedConversations, arg.Limit, arg.Offset)
264 if err != nil {
265 return nil, err
266 }
267 defer rows.Close()
268 items := []Conversation{}
269 for rows.Next() {
270 var i Conversation
271 if err := rows.Scan(
272 &i.ConversationID,
273 &i.Slug,
274 &i.UserInitiated,
275 &i.CreatedAt,
276 &i.UpdatedAt,
277 &i.Cwd,
278 &i.Archived,
279 &i.ParentConversationID,
280 &i.Model,
281 ); err != nil {
282 return nil, err
283 }
284 items = append(items, i)
285 }
286 if err := rows.Close(); err != nil {
287 return nil, err
288 }
289 if err := rows.Err(); err != nil {
290 return nil, err
291 }
292 return items, nil
293}
294
295const listConversations = `-- name: ListConversations :many
296SELECT conversation_id, slug, user_initiated, created_at, updated_at, cwd, archived, parent_conversation_id, model FROM conversations
297WHERE archived = FALSE AND parent_conversation_id IS NULL
298ORDER BY updated_at DESC
299LIMIT ? OFFSET ?
300`
301
302type ListConversationsParams struct {
303 Limit int64 `json:"limit"`
304 Offset int64 `json:"offset"`
305}
306
307func (q *Queries) ListConversations(ctx context.Context, arg ListConversationsParams) ([]Conversation, error) {
308 rows, err := q.db.QueryContext(ctx, listConversations, arg.Limit, arg.Offset)
309 if err != nil {
310 return nil, err
311 }
312 defer rows.Close()
313 items := []Conversation{}
314 for rows.Next() {
315 var i Conversation
316 if err := rows.Scan(
317 &i.ConversationID,
318 &i.Slug,
319 &i.UserInitiated,
320 &i.CreatedAt,
321 &i.UpdatedAt,
322 &i.Cwd,
323 &i.Archived,
324 &i.ParentConversationID,
325 &i.Model,
326 ); err != nil {
327 return nil, err
328 }
329 items = append(items, i)
330 }
331 if err := rows.Close(); err != nil {
332 return nil, err
333 }
334 if err := rows.Err(); err != nil {
335 return nil, err
336 }
337 return items, nil
338}
339
340const searchArchivedConversations = `-- name: SearchArchivedConversations :many
341SELECT conversation_id, slug, user_initiated, created_at, updated_at, cwd, archived, parent_conversation_id, model FROM conversations
342WHERE slug LIKE '%' || ? || '%' AND archived = TRUE
343ORDER BY updated_at DESC
344LIMIT ? OFFSET ?
345`
346
347type SearchArchivedConversationsParams struct {
348 Column1 *string `json:"column_1"`
349 Limit int64 `json:"limit"`
350 Offset int64 `json:"offset"`
351}
352
353func (q *Queries) SearchArchivedConversations(ctx context.Context, arg SearchArchivedConversationsParams) ([]Conversation, error) {
354 rows, err := q.db.QueryContext(ctx, searchArchivedConversations, arg.Column1, arg.Limit, arg.Offset)
355 if err != nil {
356 return nil, err
357 }
358 defer rows.Close()
359 items := []Conversation{}
360 for rows.Next() {
361 var i Conversation
362 if err := rows.Scan(
363 &i.ConversationID,
364 &i.Slug,
365 &i.UserInitiated,
366 &i.CreatedAt,
367 &i.UpdatedAt,
368 &i.Cwd,
369 &i.Archived,
370 &i.ParentConversationID,
371 &i.Model,
372 ); err != nil {
373 return nil, err
374 }
375 items = append(items, i)
376 }
377 if err := rows.Close(); err != nil {
378 return nil, err
379 }
380 if err := rows.Err(); err != nil {
381 return nil, err
382 }
383 return items, nil
384}
385
386const searchConversations = `-- name: SearchConversations :many
387SELECT conversation_id, slug, user_initiated, created_at, updated_at, cwd, archived, parent_conversation_id, model FROM conversations
388WHERE slug LIKE '%' || ? || '%' AND archived = FALSE AND parent_conversation_id IS NULL
389ORDER BY updated_at DESC
390LIMIT ? OFFSET ?
391`
392
393type SearchConversationsParams struct {
394 Column1 *string `json:"column_1"`
395 Limit int64 `json:"limit"`
396 Offset int64 `json:"offset"`
397}
398
399func (q *Queries) SearchConversations(ctx context.Context, arg SearchConversationsParams) ([]Conversation, error) {
400 rows, err := q.db.QueryContext(ctx, searchConversations, arg.Column1, arg.Limit, arg.Offset)
401 if err != nil {
402 return nil, err
403 }
404 defer rows.Close()
405 items := []Conversation{}
406 for rows.Next() {
407 var i Conversation
408 if err := rows.Scan(
409 &i.ConversationID,
410 &i.Slug,
411 &i.UserInitiated,
412 &i.CreatedAt,
413 &i.UpdatedAt,
414 &i.Cwd,
415 &i.Archived,
416 &i.ParentConversationID,
417 &i.Model,
418 ); err != nil {
419 return nil, err
420 }
421 items = append(items, i)
422 }
423 if err := rows.Close(); err != nil {
424 return nil, err
425 }
426 if err := rows.Err(); err != nil {
427 return nil, err
428 }
429 return items, nil
430}
431
432const searchConversationsWithMessages = `-- name: SearchConversationsWithMessages :many
433SELECT DISTINCT c.conversation_id, c.slug, c.user_initiated, c.created_at, c.updated_at, c.cwd, c.archived, c.parent_conversation_id, c.model FROM conversations c
434LEFT JOIN messages m ON c.conversation_id = m.conversation_id AND m.type IN ('user', 'agent')
435WHERE c.archived = FALSE
436 AND (
437 c.slug LIKE '%' || ? || '%'
438 OR json_extract(m.user_data, '$.text') LIKE '%' || ? || '%'
439 OR m.llm_data LIKE '%' || ? || '%'
440 )
441ORDER BY c.updated_at DESC
442LIMIT ? OFFSET ?
443`
444
445type SearchConversationsWithMessagesParams struct {
446 Column1 *string `json:"column_1"`
447 Column2 *string `json:"column_2"`
448 Column3 *string `json:"column_3"`
449 Limit int64 `json:"limit"`
450 Offset int64 `json:"offset"`
451}
452
453// Search conversations by slug OR message content (user messages and agent responses, not system prompts)
454// Includes both top-level conversations and subagent conversations
455func (q *Queries) SearchConversationsWithMessages(ctx context.Context, arg SearchConversationsWithMessagesParams) ([]Conversation, error) {
456 rows, err := q.db.QueryContext(ctx, searchConversationsWithMessages,
457 arg.Column1,
458 arg.Column2,
459 arg.Column3,
460 arg.Limit,
461 arg.Offset,
462 )
463 if err != nil {
464 return nil, err
465 }
466 defer rows.Close()
467 items := []Conversation{}
468 for rows.Next() {
469 var i Conversation
470 if err := rows.Scan(
471 &i.ConversationID,
472 &i.Slug,
473 &i.UserInitiated,
474 &i.CreatedAt,
475 &i.UpdatedAt,
476 &i.Cwd,
477 &i.Archived,
478 &i.ParentConversationID,
479 &i.Model,
480 ); err != nil {
481 return nil, err
482 }
483 items = append(items, i)
484 }
485 if err := rows.Close(); err != nil {
486 return nil, err
487 }
488 if err := rows.Err(); err != nil {
489 return nil, err
490 }
491 return items, nil
492}
493
494const unarchiveConversation = `-- name: UnarchiveConversation :one
495UPDATE conversations
496SET archived = FALSE, updated_at = CURRENT_TIMESTAMP
497WHERE conversation_id = ?
498RETURNING conversation_id, slug, user_initiated, created_at, updated_at, cwd, archived, parent_conversation_id, model
499`
500
501func (q *Queries) UnarchiveConversation(ctx context.Context, conversationID string) (Conversation, error) {
502 row := q.db.QueryRowContext(ctx, unarchiveConversation, conversationID)
503 var i Conversation
504 err := row.Scan(
505 &i.ConversationID,
506 &i.Slug,
507 &i.UserInitiated,
508 &i.CreatedAt,
509 &i.UpdatedAt,
510 &i.Cwd,
511 &i.Archived,
512 &i.ParentConversationID,
513 &i.Model,
514 )
515 return i, err
516}
517
518const updateConversationCwd = `-- name: UpdateConversationCwd :one
519UPDATE conversations
520SET cwd = ?, updated_at = CURRENT_TIMESTAMP
521WHERE conversation_id = ?
522RETURNING conversation_id, slug, user_initiated, created_at, updated_at, cwd, archived, parent_conversation_id, model
523`
524
525type UpdateConversationCwdParams struct {
526 Cwd *string `json:"cwd"`
527 ConversationID string `json:"conversation_id"`
528}
529
530func (q *Queries) UpdateConversationCwd(ctx context.Context, arg UpdateConversationCwdParams) (Conversation, error) {
531 row := q.db.QueryRowContext(ctx, updateConversationCwd, arg.Cwd, arg.ConversationID)
532 var i Conversation
533 err := row.Scan(
534 &i.ConversationID,
535 &i.Slug,
536 &i.UserInitiated,
537 &i.CreatedAt,
538 &i.UpdatedAt,
539 &i.Cwd,
540 &i.Archived,
541 &i.ParentConversationID,
542 &i.Model,
543 )
544 return i, err
545}
546
547const updateConversationModel = `-- name: UpdateConversationModel :exec
548UPDATE conversations
549SET model = ?
550WHERE conversation_id = ? AND model IS NULL
551`
552
553type UpdateConversationModelParams struct {
554 Model *string `json:"model"`
555 ConversationID string `json:"conversation_id"`
556}
557
558func (q *Queries) UpdateConversationModel(ctx context.Context, arg UpdateConversationModelParams) error {
559 _, err := q.db.ExecContext(ctx, updateConversationModel, arg.Model, arg.ConversationID)
560 return err
561}
562
563const updateConversationSlug = `-- name: UpdateConversationSlug :one
564UPDATE conversations
565SET slug = ?, updated_at = CURRENT_TIMESTAMP
566WHERE conversation_id = ?
567RETURNING conversation_id, slug, user_initiated, created_at, updated_at, cwd, archived, parent_conversation_id, model
568`
569
570type UpdateConversationSlugParams struct {
571 Slug *string `json:"slug"`
572 ConversationID string `json:"conversation_id"`
573}
574
575func (q *Queries) UpdateConversationSlug(ctx context.Context, arg UpdateConversationSlugParams) (Conversation, error) {
576 row := q.db.QueryRowContext(ctx, updateConversationSlug, arg.Slug, arg.ConversationID)
577 var i Conversation
578 err := row.Scan(
579 &i.ConversationID,
580 &i.Slug,
581 &i.UserInitiated,
582 &i.CreatedAt,
583 &i.UpdatedAt,
584 &i.Cwd,
585 &i.Archived,
586 &i.ParentConversationID,
587 &i.Model,
588 )
589 return i, err
590}
591
592const updateConversationTimestamp = `-- name: UpdateConversationTimestamp :exec
593UPDATE conversations
594SET updated_at = CURRENT_TIMESTAMP
595WHERE conversation_id = ?
596`
597
598func (q *Queries) UpdateConversationTimestamp(ctx context.Context, conversationID string) error {
599 _, err := q.db.ExecContext(ctx, updateConversationTimestamp, conversationID)
600 return err
601}