feat(query-api): add richer stats and retention

This commit is contained in:
William Valentin
2026-03-26 11:22:34 -07:00
parent fdfcb50e80
commit 43877a5448
10 changed files with 583 additions and 85 deletions
+11
View File
@@ -19,6 +19,7 @@ type EventsFilter struct {
EventType string
Framework string
ClientID string
Since *time.Time // if nil, defaults to 24h ago
}
func (d *DB) ListRecentEvents(ctx context.Context, f EventsFilter) ([]EventRow, error) {
@@ -29,10 +30,20 @@ func (d *DB) ListRecentEvents(ctx context.Context, f EventsFilter) ([]EventRow,
f.Limit = 1000
}
since := f.Since
if since == nil {
t := time.Now().Add(-24 * time.Hour)
since = &t
}
query := "SELECT event_id, ts, type, payload FROM events WHERE 1=1"
args := []any{}
argN := 1
query += fmt.Sprintf(" AND ts >= $%d", argN)
args = append(args, *since)
argN++
if f.EventType != "" {
query += fmt.Sprintf(" AND type = $%d", argN)
args = append(args, f.EventType)