data layer

This commit is contained in:
2026-05-25 08:38:26 +07:00
parent 4e8c11d545
commit a428170fef
81 changed files with 3941 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
package model
import "time"
// Profile is the unified-profile shape returned by /profiles/:id. The
// underlying table is owned by cdp-ingestion (identity-resolution).
type Profile struct {
ID string `json:"id"`
WorkspaceID string `json:"workspace_id"`
UserID string `json:"user_id,omitempty"`
AnonymousIDs []string `json:"anonymous_ids,omitempty"`
Traits map[string]any `json:"traits,omitempty"`
FirstSeenAt time.Time `json:"first_seen_at"`
LastSeenAt time.Time `json:"last_seen_at"`
}
// SavedQuery mirrors the saved_queries table.
type SavedQuery struct {
ID string `json:"id"`
WorkspaceID string `json:"workspace_id"`
OwnerID string `json:"owner_id,omitempty"`
Name string `json:"name"`
Kind string `json:"kind"`
Spec map[string]any `json:"spec"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}

View File

@@ -0,0 +1,47 @@
// Package model defines domain types passed between layers.
package model
import "time"
// EventTable enumerates the four ClickHouse event tables written by
// cdp-ingestion. Used to whitelist `events` queries so we never interpolate
// an untrusted table name into a template.
type EventTable string
const (
EventTableTrack EventTable = "events_track"
EventTableIdentify EventTable = "events_identify"
EventTablePage EventTable = "events_page"
EventTableGroup EventTable = "events_group"
)
func (t EventTable) Valid() bool {
switch t {
case EventTableTrack, EventTableIdentify, EventTablePage, EventTableGroup:
return true
}
return false
}
// EventQuery is the parsed filter passed to repo.QueryEvents.
type EventQuery struct {
WorkspaceID string
Table EventTable
From time.Time
To time.Time
UserID string // optional
AnonymousID string // optional
EventName string // optional, only meaningful when Table == events_track
Limit int
Offset int
}
// QueryResult is a generic columns+rows envelope returned by Query API endpoints.
type QueryResult struct {
Columns []string `json:"columns"`
Rows [][]any `json:"rows"`
RowCount int `json:"row_count"`
DurationMS int64 `json:"duration_ms"`
CacheHit bool `json:"cache_hit"`
Meta map[string]any `json:"meta,omitempty"`
}