2022-09-01 14:58:23 -05:00
|
|
|
-- name: InsertAgentStat :one
|
|
|
|
|
INSERT INTO
|
|
|
|
|
agent_stats (
|
|
|
|
|
id,
|
|
|
|
|
created_at,
|
|
|
|
|
user_id,
|
|
|
|
|
workspace_id,
|
|
|
|
|
template_id,
|
|
|
|
|
agent_id,
|
|
|
|
|
payload
|
|
|
|
|
)
|
|
|
|
|
VALUES
|
|
|
|
|
($1, $2, $3, $4, $5, $6, $7) RETURNING *;
|
|
|
|
|
|
2022-09-19 14:11:18 -05:00
|
|
|
-- name: GetLatestAgentStat :one
|
|
|
|
|
SELECT * FROM agent_stats WHERE agent_id = $1 ORDER BY created_at DESC LIMIT 1;
|
|
|
|
|
|
2022-09-01 14:58:23 -05:00
|
|
|
-- name: GetTemplateDAUs :many
|
|
|
|
|
select
|
|
|
|
|
(created_at at TIME ZONE 'UTC')::date as date,
|
2022-09-09 14:30:31 -05:00
|
|
|
user_id
|
2022-09-01 14:58:23 -05:00
|
|
|
from
|
|
|
|
|
agent_stats
|
|
|
|
|
where template_id = $1
|
|
|
|
|
group by
|
2022-09-09 14:30:31 -05:00
|
|
|
date, user_id
|
2022-09-01 14:58:23 -05:00
|
|
|
order by
|
|
|
|
|
date asc;
|
|
|
|
|
|
|
|
|
|
-- name: DeleteOldAgentStats :exec
|
|
|
|
|
DELETE FROM AGENT_STATS WHERE created_at < now() - interval '30 days';
|