Skip to content

Commit 6fc3451

Browse files
committed
add queries
1 parent 5644197 commit 6fc3451

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
-- name: InsertWorkspaceAppAuditSession :one
2+
INSERT INTO
3+
workspace_app_audit_sessions (
4+
agent_id,
5+
app_id,
6+
user_id,
7+
ip,
8+
started_at,
9+
updated_at
10+
)
11+
VALUES
12+
(
13+
$1,
14+
$2,
15+
$3,
16+
$4,
17+
$5,
18+
$6
19+
)
20+
RETURNING
21+
id;
22+
23+
-- name: UpdateWorkspaceAppAuditSession :many
24+
--
25+
-- Return ID to determine if a row was updated or not. This table isn't strict
26+
-- about uniqueness, so we need to know if we updated an existing row or not.
27+
UPDATE
28+
workspace_app_audit_sessions
29+
SET
30+
updated_at = @updated_at
31+
WHERE
32+
agent_id = @agent_id
33+
AND app_id IS NOT DISTINCT FROM @app_id
34+
AND user_id IS NOT DISTINCT FROM @user_id
35+
AND ip IS NOT DISTINCT FROM @ip
36+
AND updated_at > NOW() - (@stale_interval_ms::bigint || ' ms')::interval
37+
RETURNING
38+
id;

0 commit comments

Comments
 (0)