Documentation
¶
Overview ¶
Package store owns the Postgres connection pool and schema migrations.
Index ¶
- Variables
- type Agent
- type Attachment
- type IngestToken
- type Issue
- type ListIssuesParams
- type Project
- type QueueItem
- type Store
- func (s *Store) AckIssue(ctx context.Context, agentID int64, issueID uuid.UUID) error
- func (s *Store) AckIssues(ctx context.Context, agentID int64, issueIDs []uuid.UUID) error
- func (s *Store) AddAttachment(ctx context.Context, a Attachment) error
- func (s *Store) AgentByTokenHash(ctx context.Context, hash string) (Agent, error)
- func (s *Store) AgentQueueDepth(ctx context.Context, agentID int64) (int, error)
- func (s *Store) Close()
- func (s *Store) CreateAgent(ctx context.Context, name, tokenHash string, createdBy *int64) (Agent, error)
- func (s *Store) CreateIngestToken(ctx context.Context, tokenHash, label string, projectID *int64) (IngestToken, error)
- func (s *Store) CreateIssue(ctx context.Context, iss Issue) error
- func (s *Store) CreateProject(ctx context.Context, slug, name, description string) (Project, error)
- func (s *Store) CreateUser(ctx context.Context, telegramID int64, name, role string) (User, error)
- func (s *Store) DeleteAgent(ctx context.Context, id int64) error
- func (s *Store) DeleteIngestToken(ctx context.Context, id int64) error
- func (s *Store) DeleteProject(ctx context.Context, id int64) error
- func (s *Store) DeleteUser(ctx context.Context, id int64) error
- func (s *Store) GetAttachment(ctx context.Context, id uuid.UUID) (Attachment, error)
- func (s *Store) GetIssue(ctx context.Context, id uuid.UUID) (Issue, []Attachment, error)
- func (s *Store) GetProjectBySlug(ctx context.Context, slug string) (Project, error)
- func (s *Store) GetUserByTelegramID(ctx context.Context, tgID int64) (User, error)
- func (s *Store) InboxCount(ctx context.Context) (int, error)
- func (s *Store) IngestTokenByHash(ctx context.Context, hash string) (IngestToken, error)
- func (s *Store) IssueCount(ctx context.Context) (int, error)
- func (s *Store) ListAgentPerms(ctx context.Context, agentID int64) (projectIDs []int64, inbox bool, err error)
- func (s *Store) ListAgents(ctx context.Context) ([]Agent, error)
- func (s *Store) ListIngestTokens(ctx context.Context) ([]IngestToken, error)
- func (s *Store) ListIssues(ctx context.Context, p ListIssuesParams) ([]Issue, error)
- func (s *Store) ListProjects(ctx context.Context) ([]Project, error)
- func (s *Store) ListUsers(ctx context.Context) ([]User, error)
- func (s *Store) QueueForAgent(ctx context.Context, agentID int64, limit int) ([]QueueItem, error)
- func (s *Store) SetAgentPerms(ctx context.Context, agentID int64, projectIDs []int64, inbox bool) error
- func (s *Store) SetIssueProject(ctx context.Context, issueID uuid.UUID, projectID *int64) error
- func (s *Store) TouchAgent(ctx context.Context, agentID int64) error
- type User
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("store: not found")
ErrNotFound is returned by single-row lookups when no row matches.
Functions ¶
This section is empty.
Types ¶
type Agent ¶
type Agent struct {
ID int64
Name string
TokenHash string
CreatedBy *int64
CreatedAt time.Time
LastSeenAt *time.Time
}
Agent is a machine consumer that drains issues via a bearer token.
type Attachment ¶
type Attachment struct {
ID uuid.UUID
IssueID uuid.UUID
S3Key string
Mime string
SizeBytes int64
Filename string
}
Attachment is a file stored in blob storage and linked to an issue.
type IngestToken ¶
type IngestToken struct {
ID int64
TokenHash string
Label string
ProjectID *int64
CreatedAt time.Time
}
IngestToken authorizes API submissions, optionally scoped to a project.
type Issue ¶
type Issue struct {
ID uuid.UUID
ProjectID *int64
Source string
AuthorUserID *int64
Body string
Meta map[string]any
CreatedAt time.Time
}
Issue is a captured report. A nil ProjectID means the inbox.
type ListIssuesParams ¶
ListIssuesParams filters a browse query over issues.
type QueueItem ¶
type QueueItem struct {
Issue Issue
Attachments []Attachment
}
QueueItem pairs an issue with its attachments for agent delivery.
type Store ¶
Store wraps the pgx connection pool shared by all repositories.
func Open ¶
Open connects a pgxpool to databaseURL, pings it, and applies goose migrations (embedded) via the pgx stdlib driver.
func (*Store) AckIssue ¶
AckIssue marks issueID acked for agentID. It is idempotent and returns ErrNotFound if the issue does not exist.
func (*Store) AckIssues ¶
AckIssues bulk-acks issueIDs for agentID, silently skipping ids that do not exist. It is idempotent.
func (*Store) AddAttachment ¶
func (s *Store) AddAttachment(ctx context.Context, a Attachment) error
AddAttachment inserts a.
func (*Store) AgentByTokenHash ¶
AgentByTokenHash looks up an agent by its token hash.
func (*Store) AgentQueueDepth ¶
AgentQueueDepth returns how many issues the agent is permitted to see and has not yet acked. It reuses the exact predicate from QueueForAgent.
func (*Store) CreateAgent ¶
func (s *Store) CreateAgent(ctx context.Context, name, tokenHash string, createdBy *int64) (Agent, error)
CreateAgent inserts an agent and returns the stored row.
func (*Store) CreateIngestToken ¶
func (s *Store) CreateIngestToken(ctx context.Context, tokenHash, label string, projectID *int64) (IngestToken, error)
CreateIngestToken inserts an ingest token and returns the stored row.
func (*Store) CreateIssue ¶
CreateIssue inserts iss using its caller-provided ID. A nil Meta is stored as an empty JSON object.
func (*Store) CreateProject ¶
CreateProject inserts a project and returns the stored row.
func (*Store) CreateUser ¶
CreateUser inserts a user and returns the stored row.
func (*Store) DeleteAgent ¶
DeleteAgent removes an agent by id.
func (*Store) DeleteIngestToken ¶
DeleteIngestToken removes an ingest token by id.
func (*Store) DeleteProject ¶
DeleteProject removes a project by id.
func (*Store) DeleteUser ¶
DeleteUser removes a user by id.
func (*Store) GetAttachment ¶
GetAttachment loads a single attachment by id.
func (*Store) GetProjectBySlug ¶
GetProjectBySlug looks up a project by slug.
func (*Store) GetUserByTelegramID ¶
GetUserByTelegramID looks up a user by Telegram id.
func (*Store) InboxCount ¶
InboxCount returns the number of issues that have not been tagged to a project (project_id IS NULL).
func (*Store) IngestTokenByHash ¶
IngestTokenByHash looks up an ingest token by its hash.
func (*Store) IssueCount ¶
IssueCount returns the total number of issues.
func (*Store) ListAgentPerms ¶
func (s *Store) ListAgentPerms(ctx context.Context, agentID int64) (projectIDs []int64, inbox bool, err error)
ListAgentPerms returns the agent's scoped project ids and whether it has the inbox permission.
func (*Store) ListAgents ¶
ListAgents returns all agents ordered by id.
func (*Store) ListIngestTokens ¶
func (s *Store) ListIngestTokens(ctx context.Context) ([]IngestToken, error)
ListIngestTokens returns all ingest tokens ordered by id.
func (*Store) ListIssues ¶
ListIssues returns issues newest first, applying the project/inbox and since filters. Attachments are not loaded.
func (*Store) ListProjects ¶
ListProjects returns all projects ordered by id.
func (*Store) QueueForAgent ¶
QueueForAgent returns issues the agent is permitted to see and has not yet acked, oldest first, with their attachments attached.
func (*Store) SetAgentPerms ¶
func (s *Store) SetAgentPerms(ctx context.Context, agentID int64, projectIDs []int64, inbox bool) error
SetAgentPerms replaces all permission rows for the agent. Each projectID becomes a scoped row; inbox adds a NULL project_id row.
func (*Store) SetIssueProject ¶
SetIssueProject moves an issue to projectID (nil = inbox). Returns ErrNotFound if the issue does not exist.