Documentation
¶
Overview ¶
Package postgres implements the storage interfaces using PostgreSQL with pgvector and ltree.
Index ¶
- type Config
- type DB
- type DBTX
- type EdgeStore
- func (s *EdgeStore) Create(ctx context.Context, edge *model.Edge) error
- func (s *EdgeStore) Delete(ctx context.Context, id model.ID) error
- func (s *EdgeStore) EdgesBetween(ctx context.Context, fromID, toID model.ID) ([]model.Edge, error)
- func (s *EdgeStore) EdgesFrom(ctx context.Context, entryID model.ID, filter storage.EdgeFilter) ([]model.Edge, error)
- func (s *EdgeStore) EdgesTo(ctx context.Context, entryID model.ID, filter storage.EdgeFilter) ([]model.Edge, error)
- func (s *EdgeStore) FindConflicts(ctx context.Context, entryID model.ID) ([]model.Entry, error)
- func (s *EdgeStore) Get(ctx context.Context, id model.ID) (*model.Edge, error)
- type EntryStore
- func (s *EntryStore) Create(ctx context.Context, entry *model.Entry) error
- func (s *EntryStore) CreateOrUpdate(ctx context.Context, entry *model.Entry) (*model.Entry, error)
- func (s *EntryStore) Delete(ctx context.Context, id model.ID) error
- func (s *EntryStore) DeleteExpired(ctx context.Context) (int64, error)
- func (s *EntryStore) Get(ctx context.Context, id model.ID) (*model.Entry, error)
- func (s *EntryStore) List(ctx context.Context, filter storage.EntryFilter) ([]model.Entry, error)
- func (s *EntryStore) SearchSimilar(ctx context.Context, query []float32, scope string, ...) ([]storage.SimilarityResult, error)
- func (s *EntryStore) Update(ctx context.Context, entry *model.Entry) error
- type ScopeStore
- func (s *ScopeStore) Delete(ctx context.Context, path string) error
- func (s *ScopeStore) EnsureHierarchy(ctx context.Context, path string) error
- func (s *ScopeStore) Get(ctx context.Context, path string) (*model.Scope, error)
- func (s *ScopeStore) List(ctx context.Context) ([]model.Scope, error)
- func (s *ScopeStore) ListChildren(ctx context.Context, parentPath string) ([]model.Scope, error)
- func (s *ScopeStore) ListDescendants(ctx context.Context, ancestorPath string) ([]model.Scope, error)
- func (s *ScopeStore) Upsert(ctx context.Context, scope *model.Scope) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// DSN is the PostgreSQL connection string.
// Example: "postgres://user:pass@localhost:5432/known?sslmode=disable"
DSN string
// MaxConns sets the maximum number of connections in the pool.
// Zero uses pgxpool's default.
MaxConns int32
}
Config holds PostgreSQL connection parameters.
type DB ¶
DB wraps a pgxpool and provides access to repository implementations.
func (*DB) WithTx ¶
WithTx runs fn within a database transaction. The transaction is stored in the context, so any repo method called with the returned context will participate in the same transaction. The transaction is committed if fn returns nil, and rolled back otherwise.
If a transaction is already active in the context, fn runs within the existing transaction (no nesting).
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
}
DBTX is the common interface between *pgxpool.Pool and pgx.Tx, allowing repo methods to operate within or outside a transaction.
type EdgeStore ¶
type EdgeStore struct {
// contains filtered or unexported fields
}
EdgeStore implements storage.EdgeRepo using PostgreSQL.
func (*EdgeStore) Create ¶
Create persists a new edge. When called within a transaction (via context), both the edge type registration and edge insert use the same transaction. Without a caller-provided transaction, each operation runs independently, which is acceptable since edge type registration uses ON CONFLICT DO NOTHING.
func (*EdgeStore) EdgesBetween ¶
EdgesBetween returns edges from source to target.
func (*EdgeStore) EdgesFrom ¶
func (s *EdgeStore) EdgesFrom(ctx context.Context, entryID model.ID, filter storage.EdgeFilter) ([]model.Edge, error)
EdgesFrom returns all outgoing edges from the given entry.
func (*EdgeStore) EdgesTo ¶
func (s *EdgeStore) EdgesTo(ctx context.Context, entryID model.ID, filter storage.EdgeFilter) ([]model.Edge, error)
EdgesTo returns all incoming edges to the given entry.
func (*EdgeStore) FindConflicts ¶
FindConflicts returns entries that have a "contradicts" edge involving the given entry.
type EntryStore ¶
type EntryStore struct {
// contains filtered or unexported fields
}
EntryStore implements storage.EntryRepo using PostgreSQL with pgvector.
func (*EntryStore) Create ¶
Create persists a new entry. It automatically ensures the scope hierarchy exists. If not already within a transaction, wraps both operations in one for atomicity.
func (*EntryStore) CreateOrUpdate ¶
CreateOrUpdate inserts a new entry or updates an existing one with the same content hash and scope. Uses ON CONFLICT (content_hash, scope) for idempotent upserts. If not already within a transaction, wraps both operations in one for atomicity.
func (*EntryStore) DeleteExpired ¶
func (s *EntryStore) DeleteExpired(ctx context.Context) (int64, error)
DeleteExpired removes entries whose ExpiresAt is in the past.
func (*EntryStore) List ¶
func (s *EntryStore) List(ctx context.Context, filter storage.EntryFilter) ([]model.Entry, error)
List returns entries matching the given filter.
func (*EntryStore) SearchSimilar ¶
func (s *EntryStore) SearchSimilar(ctx context.Context, query []float32, scope string, metric storage.SimilarityMetric, limit int) ([]storage.SimilarityResult, error)
SearchSimilar finds entries with embeddings similar to the query vector.
type ScopeStore ¶
type ScopeStore struct {
// contains filtered or unexported fields
}
ScopeStore implements storage.ScopeRepo using PostgreSQL with ltree.
func (*ScopeStore) Delete ¶
func (s *ScopeStore) Delete(ctx context.Context, path string) error
Delete removes a scope by path.
func (*ScopeStore) EnsureHierarchy ¶
func (s *ScopeStore) EnsureHierarchy(ctx context.Context, path string) error
EnsureHierarchy ensures that all ancestor scopes exist for a given scope path. For example, given "project.auth.oauth", it ensures "project", "project.auth", and "project.auth.oauth" all exist.
func (*ScopeStore) ListChildren ¶
ListChildren returns direct child scopes of the given parent path.
func (*ScopeStore) ListDescendants ¶
func (s *ScopeStore) ListDescendants(ctx context.Context, ancestorPath string) ([]model.Scope, error)
ListDescendants returns all descendant scopes of the given ancestor path.