forked from stacklok/codegate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueries.sql
More file actions
99 lines (86 loc) · 1.97 KB
/
queries.sql
File metadata and controls
99 lines (86 loc) · 1.97 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
-- name: CreatePrompt :one
INSERT INTO prompts (
id,
timestamp,
provider,
request,
type
) VALUES (?, ?, ?, ?, ?) RETURNING *;
-- name: GetPrompt :one
SELECT * FROM prompts WHERE id = ?;
-- name: ListPrompts :many
SELECT * FROM prompts
ORDER BY timestamp DESC
LIMIT ? OFFSET ?;
-- name: CreateOutput :one
INSERT INTO outputs (
id,
prompt_id,
timestamp,
output
) VALUES (?, ?, ?, ?) RETURNING *;
-- name: GetOutput :one
SELECT * FROM outputs WHERE id = ?;
-- name: GetOutputsByPromptId :many
SELECT * FROM outputs
WHERE prompt_id = ?
ORDER BY timestamp DESC;
-- name: CreateAlert :one
INSERT INTO alerts (
id,
prompt_id,
output_id,
code_snippet,
trigger_string,
trigger_type,
trigger_category,
timestamp
) VALUES (?, ?, ?, ?, ?, ?, ?, ?) RETURNING *;
-- name: GetAlert :one
SELECT * FROM alerts WHERE id = ?;
-- name: ListAlertsByPrompt :many
SELECT * FROM alerts
WHERE prompt_id = ?
ORDER BY timestamp DESC;
-- name: GetSettings :one
SELECT * FROM settings ORDER BY id LIMIT 1;
-- name: UpsertSettings :one
INSERT INTO settings (
id,
ip,
port,
llm_model,
system_prompt,
other_settings
) VALUES (?, ?, ?, ?, ?, ?)
ON CONFLICT(id) DO UPDATE SET
ip = excluded.ip,
port = excluded.port,
llm_model = excluded.llm_model,
system_prompt = excluded.system_prompt,
other_settings = excluded.other_settings
RETURNING *;
-- name: GetPromptWithOutputsAndAlerts :many
SELECT
p.*,
o.id as output_id,
o.output,
a.id as alert_id,
a.code_snippet,
a.trigger_string,
a.trigger_type,
a.trigger_category
FROM prompts p
LEFT JOIN outputs o ON p.id = o.prompt_id
LEFT JOIN alerts a ON p.id = a.prompt_id
WHERE p.id = ?
ORDER BY o.timestamp DESC, a.timestamp DESC;
-- name: GetPromptWithOutputs :many
SELECT
p.*,
o.id as output_id,
o.output,
o.timestamp as output_timestamp
FROM prompts p
LEFT JOIN outputs o ON p.id = o.prompt_id
ORDER BY o.timestamp DESC;