store

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package store owns the Postgres connection pool and schema migrations.

Index

Constants

This section is empty.

Variables

View Source
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

type ListIssuesParams struct {
	ProjectID *int64
	InboxOnly bool
	Since     *time.Time
	Limit     int
}

ListIssuesParams filters a browse query over issues.

type Project

type Project struct {
	ID          int64
	Slug        string
	Name        string
	Description string
	CreatedAt   time.Time
}

Project groups issues under a stable slug.

type QueueItem

type QueueItem struct {
	Issue       Issue
	Attachments []Attachment
}

QueueItem pairs an issue with its attachments for agent delivery.

type Store

type Store struct {
	Pool *pgxpool.Pool
}

Store wraps the pgx connection pool shared by all repositories.

func Open

func Open(ctx context.Context, databaseURL string) (*Store, error)

Open connects a pgxpool to databaseURL, pings it, and applies goose migrations (embedded) via the pgx stdlib driver.

func (*Store) AckIssue

func (s *Store) AckIssue(ctx context.Context, agentID int64, issueID uuid.UUID) error

AckIssue marks issueID acked for agentID. It is idempotent and returns ErrNotFound if the issue does not exist.

func (*Store) AckIssues

func (s *Store) AckIssues(ctx context.Context, agentID int64, issueIDs []uuid.UUID) error

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

func (s *Store) AgentByTokenHash(ctx context.Context, hash string) (Agent, error)

AgentByTokenHash looks up an agent by its token hash.

func (*Store) AgentQueueDepth

func (s *Store) AgentQueueDepth(ctx context.Context, agentID int64) (int, error)

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) Close

func (s *Store) Close()

Close releases the connection pool.

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

func (s *Store) CreateIssue(ctx context.Context, iss Issue) error

CreateIssue inserts iss using its caller-provided ID. A nil Meta is stored as an empty JSON object.

func (*Store) CreateProject

func (s *Store) CreateProject(ctx context.Context, slug, name, description string) (Project, error)

CreateProject inserts a project and returns the stored row.

func (*Store) CreateUser

func (s *Store) CreateUser(ctx context.Context, telegramID int64, name, role string) (User, error)

CreateUser inserts a user and returns the stored row.

func (*Store) DeleteAgent

func (s *Store) DeleteAgent(ctx context.Context, id int64) error

DeleteAgent removes an agent by id.

func (*Store) DeleteIngestToken

func (s *Store) DeleteIngestToken(ctx context.Context, id int64) error

DeleteIngestToken removes an ingest token by id.

func (*Store) DeleteProject

func (s *Store) DeleteProject(ctx context.Context, id int64) error

DeleteProject removes a project by id.

func (*Store) DeleteUser

func (s *Store) DeleteUser(ctx context.Context, id int64) error

DeleteUser removes a user by id.

func (*Store) GetAttachment

func (s *Store) GetAttachment(ctx context.Context, id uuid.UUID) (Attachment, error)

GetAttachment loads a single attachment by id.

func (*Store) GetIssue

func (s *Store) GetIssue(ctx context.Context, id uuid.UUID) (Issue, []Attachment, error)

GetIssue loads an issue and its attachments ordered by filename.

func (*Store) GetProjectBySlug

func (s *Store) GetProjectBySlug(ctx context.Context, slug string) (Project, error)

GetProjectBySlug looks up a project by slug.

func (*Store) GetUserByTelegramID

func (s *Store) GetUserByTelegramID(ctx context.Context, tgID int64) (User, error)

GetUserByTelegramID looks up a user by Telegram id.

func (*Store) InboxCount

func (s *Store) InboxCount(ctx context.Context) (int, error)

InboxCount returns the number of issues that have not been tagged to a project (project_id IS NULL).

func (*Store) IngestTokenByHash

func (s *Store) IngestTokenByHash(ctx context.Context, hash string) (IngestToken, error)

IngestTokenByHash looks up an ingest token by its hash.

func (*Store) IssueCount

func (s *Store) IssueCount(ctx context.Context) (int, error)

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

func (s *Store) ListAgents(ctx context.Context) ([]Agent, error)

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

func (s *Store) ListIssues(ctx context.Context, p ListIssuesParams) ([]Issue, error)

ListIssues returns issues newest first, applying the project/inbox and since filters. Attachments are not loaded.

func (*Store) ListProjects

func (s *Store) ListProjects(ctx context.Context) ([]Project, error)

ListProjects returns all projects ordered by id.

func (*Store) ListUsers

func (s *Store) ListUsers(ctx context.Context) ([]User, error)

ListUsers returns all users ordered by id.

func (*Store) QueueForAgent

func (s *Store) QueueForAgent(ctx context.Context, agentID int64, limit int) ([]QueueItem, error)

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

func (s *Store) SetIssueProject(ctx context.Context, issueID uuid.UUID, projectID *int64) error

SetIssueProject moves an issue to projectID (nil = inbox). Returns ErrNotFound if the issue does not exist.

func (*Store) TouchAgent

func (s *Store) TouchAgent(ctx context.Context, agentID int64) error

TouchAgent records that the agent was just seen.

type User

type User struct {
	ID         int64
	TelegramID int64
	Name       string
	Role       string
	CreatedAt  time.Time
}

User is a Telegram-authenticated person with an admin or member role.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL