Documentation
¶
Overview ¶
Package store provides PostgreSQL-backed data access for Creel.
Index ¶
- func NewPool(ctx context.Context, postgresURL string) (*pgxpool.Pool, error)
- func RunMigrations(postgresURL, migrationsPath string) error
- type Chunk
- type ChunkStore
- func (s *ChunkStore) ChunkIDsByTopics(ctx context.Context, topicIDs []string) ([]string, error)
- func (s *ChunkStore) Create(ctx context.Context, documentID, content string, sequence int, ...) (*Chunk, error)
- func (s *ChunkStore) Delete(ctx context.Context, id string) error
- func (s *ChunkStore) DocumentTopicID(ctx context.Context, documentID string) (string, error)
- func (s *ChunkStore) DocumentTopicIDs(ctx context.Context, docIDs []string) (map[string]string, error)
- func (s *ChunkStore) Get(ctx context.Context, id string) (*Chunk, error)
- func (s *ChunkStore) GetMultiple(ctx context.Context, ids []string) (map[string]*Chunk, error)
- func (s *ChunkStore) SetEmbeddingID(ctx context.Context, chunkID, embeddingID string) error
- type DBTX
- type Document
- type DocumentStore
- func (s *DocumentStore) Create(ctx context.Context, topicID, slug, name, docType string, ...) (*Document, error)
- func (s *DocumentStore) Delete(ctx context.Context, id string) error
- func (s *DocumentStore) Get(ctx context.Context, id string) (*Document, error)
- func (s *DocumentStore) ListByTopic(ctx context.Context, topicID string) ([]Document, error)
- func (s *DocumentStore) TopicIDForDocument(ctx context.Context, docID string) (string, error)
- func (s *DocumentStore) Update(ctx context.Context, id, name, docType string, metadata map[string]any) (*Document, error)
- type GrantStore
- type SystemAccount
- type SystemAccountKey
- type SystemAccountStore
- func (s *SystemAccountStore) Create(ctx context.Context, name, description string) (*SystemAccount, string, error)
- func (s *SystemAccountStore) Delete(ctx context.Context, id string) error
- func (s *SystemAccountStore) List(ctx context.Context) ([]SystemAccount, error)
- func (s *SystemAccountStore) LookupKeyHash(ctx context.Context, hash string) (*auth.Principal, error)
- func (s *SystemAccountStore) RevokeKey(ctx context.Context, accountID string) error
- func (s *SystemAccountStore) RotateKey(ctx context.Context, accountID string, gracePeriod time.Duration) (string, error)
- type Topic
- type TopicGrant
- type TopicStore
- func (s *TopicStore) Create(ctx context.Context, slug, name, description, owner string) (*Topic, error)
- func (s *TopicStore) Delete(ctx context.Context, id string) error
- func (s *TopicStore) Get(ctx context.Context, id string) (*Topic, error)
- func (s *TopicStore) Grant(ctx context.Context, topicID, principal, permission, grantedBy string) (*TopicGrant, error)
- func (s *TopicStore) ListForPrincipals(ctx context.Context, principals []string) ([]Topic, error)
- func (s *TopicStore) ListGrants(ctx context.Context, topicID string) ([]TopicGrant, error)
- func (s *TopicStore) Revoke(ctx context.Context, topicID, principal string) error
- func (s *TopicStore) Update(ctx context.Context, id, name, description string) (*Topic, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RunMigrations ¶
RunMigrations applies all pending database migrations.
Types ¶
type Chunk ¶
type Chunk struct {
ID string
DocumentID string
Sequence int
Content string
EmbeddingID *string
Status string
CompactedBy *string
Metadata map[string]any
CreatedAt time.Time
}
Chunk represents a stored chunk.
type ChunkStore ¶
type ChunkStore struct {
// contains filtered or unexported fields
}
ChunkStore handles chunk persistence.
func NewChunkStore ¶
func NewChunkStore(pool DBTX) *ChunkStore
NewChunkStore creates a new chunk store.
func (*ChunkStore) ChunkIDsByTopics ¶
ChunkIDsByTopics returns all active chunk IDs belonging to the given topics.
func (*ChunkStore) Create ¶
func (s *ChunkStore) Create(ctx context.Context, documentID, content string, sequence int, metadata map[string]any) (*Chunk, error)
Create inserts a new chunk and returns it.
func (*ChunkStore) Delete ¶
func (s *ChunkStore) Delete(ctx context.Context, id string) error
Delete removes a chunk.
func (*ChunkStore) DocumentTopicID ¶
DocumentTopicID returns the topic ID for a chunk's document.
func (*ChunkStore) DocumentTopicIDs ¶
func (s *ChunkStore) DocumentTopicIDs(ctx context.Context, docIDs []string) (map[string]string, error)
DocumentTopicIDs returns a mapping of document ID to topic ID for the given documents.
func (*ChunkStore) GetMultiple ¶
GetMultiple retrieves multiple chunks by ID in a single query.
func (*ChunkStore) SetEmbeddingID ¶
func (s *ChunkStore) SetEmbeddingID(ctx context.Context, chunkID, embeddingID string) error
SetEmbeddingID updates the embedding_id for a chunk.
type DBTX ¶
type DBTX interface {
Exec(ctx context.Context, sql string, arguments ...any) (pgconn.CommandTag, error)
Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
Begin(ctx context.Context) (pgx.Tx, error)
}
DBTX is the interface satisfied by *pgxpool.Pool and *pgx.Tx. All stores accept this instead of a concrete pool so that a QueryCounter (or transaction) can be substituted in tests.
type Document ¶
type Document struct {
ID string
TopicID string
Slug string
Name string
DocType string
Metadata map[string]any
CreatedAt time.Time
UpdatedAt time.Time
}
Document represents a stored document.
type DocumentStore ¶
type DocumentStore struct {
// contains filtered or unexported fields
}
DocumentStore handles document persistence.
func NewDocumentStore ¶
func NewDocumentStore(pool DBTX) *DocumentStore
NewDocumentStore creates a new document store.
func (*DocumentStore) Create ¶
func (s *DocumentStore) Create(ctx context.Context, topicID, slug, name, docType string, metadata map[string]any) (*Document, error)
Create inserts a new document.
func (*DocumentStore) Delete ¶
func (s *DocumentStore) Delete(ctx context.Context, id string) error
Delete removes a document and cascades to chunks.
func (*DocumentStore) ListByTopic ¶
ListByTopic returns documents in a topic.
func (*DocumentStore) TopicIDForDocument ¶
TopicIDForDocument returns the topic ID that owns the given document.
type GrantStore ¶
type GrantStore struct {
// contains filtered or unexported fields
}
GrantStore provides access to topic grants and ownership from PostgreSQL.
func NewGrantStore ¶
func NewGrantStore(pool DBTX) *GrantStore
NewGrantStore creates a new grant store.
func (*GrantStore) GrantsForPrincipal ¶
func (s *GrantStore) GrantsForPrincipal(ctx context.Context, principals []string) ([]auth.Grant, error)
GrantsForPrincipal returns all grants matching any of the given principals.
func (*GrantStore) TopicOwner ¶
TopicOwner returns the owner of the given topic.
type SystemAccount ¶
type SystemAccount struct {
ID string
Name string
Description string
Principal string
CreatedAt time.Time
}
SystemAccount represents a stored system account.
type SystemAccountKey ¶
type SystemAccountKey struct {
ID string
AccountID string
KeyHash string
KeyPrefix string
Status string // "active", "grace_period", "revoked"
GraceExpiresAt *time.Time
CreatedAt time.Time
RevokedAt *time.Time
}
SystemAccountKey represents a stored API key.
type SystemAccountStore ¶
type SystemAccountStore struct {
// contains filtered or unexported fields
}
SystemAccountStore handles system account and key persistence.
func NewSystemAccountStore ¶
func NewSystemAccountStore(pool DBTX) *SystemAccountStore
NewSystemAccountStore creates a new store backed by the given pool.
func (*SystemAccountStore) Create ¶
func (s *SystemAccountStore) Create(ctx context.Context, name, description string) (*SystemAccount, string, error)
Create inserts a new system account and its initial key. Returns the account and the raw API key (shown once).
func (*SystemAccountStore) Delete ¶
func (s *SystemAccountStore) Delete(ctx context.Context, id string) error
Delete removes a system account and cascades to its keys.
func (*SystemAccountStore) List ¶
func (s *SystemAccountStore) List(ctx context.Context) ([]SystemAccount, error)
List returns all system accounts.
func (*SystemAccountStore) LookupKeyHash ¶
func (s *SystemAccountStore) LookupKeyHash(ctx context.Context, hash string) (*auth.Principal, error)
LookupKeyHash implements auth.KeyLookup. It resolves a key hash to a principal by checking active and grace-period keys.
func (*SystemAccountStore) RevokeKey ¶
func (s *SystemAccountStore) RevokeKey(ctx context.Context, accountID string) error
RevokeKey immediately revokes all active keys for the account.
func (*SystemAccountStore) RotateKey ¶
func (s *SystemAccountStore) RotateKey(ctx context.Context, accountID string, gracePeriod time.Duration) (string, error)
RotateKey generates a new key for the account. If gracePeriod > 0, old active keys enter grace period; otherwise they are revoked immediately.
type Topic ¶
type Topic struct {
ID string
Slug string
Name string
Description string
Owner string
CreatedAt time.Time
UpdatedAt time.Time
}
Topic represents a stored topic.
type TopicGrant ¶
type TopicGrant struct {
ID string
TopicID string
Principal string
Permission string
GrantedBy string
CreatedAt time.Time
}
TopicGrant represents a stored topic grant.
type TopicStore ¶
type TopicStore struct {
// contains filtered or unexported fields
}
TopicStore handles topic and grant persistence.
func NewTopicStore ¶
func NewTopicStore(pool DBTX) *TopicStore
NewTopicStore creates a new topic store.
func (*TopicStore) Create ¶
func (s *TopicStore) Create(ctx context.Context, slug, name, description, owner string) (*Topic, error)
Create inserts a new topic.
func (*TopicStore) Delete ¶
func (s *TopicStore) Delete(ctx context.Context, id string) error
Delete removes a topic and cascades to grants, documents, chunks.
func (*TopicStore) Grant ¶
func (s *TopicStore) Grant(ctx context.Context, topicID, principal, permission, grantedBy string) (*TopicGrant, error)
Grant creates or updates a topic grant.
func (*TopicStore) ListForPrincipals ¶
ListForPrincipals returns topics accessible to the given principal identities. If principals is nil, returns all topics (for system accounts).
func (*TopicStore) ListGrants ¶
func (s *TopicStore) ListGrants(ctx context.Context, topicID string) ([]TopicGrant, error)
ListGrants returns all grants for a topic.