Documentation
¶
Overview ¶
Concept writes, ported from 8f2af2e:src/keepsake/store/concepts.py.
Concept reads, ported from 8f2af2e:src/keepsake/store/concepts.py with its SQL verbatim.
Package store sends every statement keepsake runs, ported from 2de90d2:src/keepsake/store/__init__.py.
Index ¶
- Constants
- Variables
- func IsUnavailable(err error) bool
- func PoolSize() (int, error)
- func Schema() (string, error)
- func SetAcquireTimeout(d time.Duration) func()
- func ValidatedSchema(name string) (string, error)
- func Verify(ctx context.Context, s *Store, schema string) error
- type ConceptStore
- func (cs *ConceptStore) Activity(ctx context.Context, tenant *uuid.UUID, limit int) ([]Revision, error)
- func (cs *ConceptStore) Create(ctx context.Context, tenant uuid.UUID, c okf.Concept, actor string) (version int, created bool, err error)
- func (cs *ConceptStore) DailyWrites(ctx context.Context, tenant *uuid.UUID, days int) ([]DailyWrite, error)
- func (cs *ConceptStore) Detail(ctx context.Context, tenant uuid.UUID, path string, limit int) (c *okf.Concept, backlinks []string, history []Revision, err error)
- func (cs *ConceptStore) Graph(ctx context.Context, tenant uuid.UUID, limit int) ([]GraphRow, error)
- func (cs *ConceptStore) Grep(ctx context.Context, tenant uuid.UUID, pattern string, limit int) ([]GrepHit, error)
- func (cs *ConceptStore) ImportMany(ctx context.Context, tenant uuid.UUID, bundle []okf.Concept, actor string) (int, error)
- func (cs *ConceptStore) List(ctx context.Context, tenant uuid.UUID, prefix string) ([]PathType, error)
- func (cs *ConceptStore) Page(ctx context.Context, tenant *uuid.UUID, prefix string, limit, offset int) (page []Summary, total int, err error)
- func (cs *ConceptStore) PoolSize() int
- func (cs *ConceptStore) Read(ctx context.Context, tenant uuid.UUID, path string) (*okf.Concept, error)
- func (cs *ConceptStore) ReadAll(ctx context.Context, tenant uuid.UUID) ([]okf.Concept, error)
- func (cs *ConceptStore) ReadWithBacklinks(ctx context.Context, tenant uuid.UUID, path string) (c *okf.Concept, backlinks []string, err error)
- func (cs *ConceptStore) Revisions(ctx context.Context, tenant uuid.UUID, limit int) ([]Revision, error)
- func (cs *ConceptStore) Search(ctx context.Context, tenant uuid.UUID, query string, limit int, prefix *string) ([]Hit, error)
- func (cs *ConceptStore) Tenants(ctx context.Context) ([]TenantCount, error)
- func (cs *ConceptStore) Totals(ctx context.Context, tenant *uuid.UUID) (Totals, error)
- func (cs *ConceptStore) Update(ctx context.Context, tenant uuid.UUID, c okf.Concept, actor string, ...) (version int, conflict *Conflict, err error)
- type Conflict
- type DailyWrite
- type GraphRow
- type GrepError
- type GrepHit
- type Hit
- type MisconfiguredDatabase
- type NotFoundError
- type PathType
- type Revision
- type Store
- func (s *Store) AdminScope(ctx context.Context, fn func(pgx.Tx) error) error
- func (s *Store) Close()
- func (s *Store) Healthy(ctx context.Context) bool
- func (s *Store) Raw(ctx context.Context, fn func(pgx.Tx) error) error
- func (s *Store) Scope(ctx context.Context, tenant uuid.UUID, fn func(pgx.Tx) error) error
- type Summary
- type TenantCount
- type Totals
Constants ¶
const ( TenantGUC = "okf.current_tenant" AdminGUC = "okf.admin" )
The only GUCs a policy may key on; the policy, the connection and the startup check share them.
const AdminPolicy = "admin_read"
AdminPolicy is the one policy the startup check exempts from reading TenantGUC.
Variables ¶
var ErrNotFound = errors.New("not found")
ErrNotFound reports that a path has no concept in the tenant's scope.
Functions ¶
func IsUnavailable ¶
IsUnavailable reports whether err means the database is down, as 2de90d2:src/keepsake/server/tools.py reads OperationalError.
func PoolSize ¶
PoolSize reads KEEPSAKE_POOL_SIZE, defaulting to 10, and refuses a bad value with a sentence.
func SetAcquireTimeout ¶
SetAcquireTimeout overrides acquireTimeout for a test and returns a restorer.
func ValidatedSchema ¶
ValidatedSchema rejects anything not a bare identifier: the name is formatted into DDL.
Types ¶
type ConceptStore ¶
type ConceptStore struct {
// contains filtered or unexported fields
}
ConceptStore writes concepts and appends their revision log.
func NewConceptStore ¶
func NewConceptStore(s *Store) *ConceptStore
func (*ConceptStore) Activity ¶
func (cs *ConceptStore) Activity(ctx context.Context, tenant *uuid.UUID, limit int) ([]Revision, error)
Activity returns the most recent limit revisions, newest first, unlike Revisions.
func (*ConceptStore) Create ¶
func (cs *ConceptStore) Create(ctx context.Context, tenant uuid.UUID, c okf.Concept, actor string) (version int, created bool, err error)
Create inserts a concept. created is false when the path is already taken.
func (*ConceptStore) DailyWrites ¶
func (cs *ConceptStore) DailyWrites(ctx context.Context, tenant *uuid.UUID, days int) ([]DailyWrite, error)
DailyWrites returns revision counts for the last days days, oldest first and zero-filled.
func (*ConceptStore) Detail ¶
func (cs *ConceptStore) Detail(ctx context.Context, tenant uuid.UUID, path string, limit int) (c *okf.Concept, backlinks []string, history []Revision, err error)
Detail is ReadWithBacklinks plus the path's newest limit revisions, in one transaction.
func (*ConceptStore) Graph ¶
Graph returns (path, type, title, links) for the first limit concepts by path.
func (*ConceptStore) Grep ¶
func (cs *ConceptStore) Grep(ctx context.Context, tenant uuid.UUID, pattern string, limit int) ([]GrepHit, error)
Grep returns (path, snippet) matches of a POSIX regex, or a *GrepError for a bad or slow one.
func (*ConceptStore) ImportMany ¶
func (cs *ConceptStore) ImportMany(ctx context.Context, tenant uuid.UUID, bundle []okf.Concept, actor string) (int, error)
ImportMany stores a bundle in one transaction, last write winning per path; err is a *NotFoundError if a path vanishes.
func (*ConceptStore) List ¶
func (cs *ConceptStore) List(ctx context.Context, tenant uuid.UUID, prefix string) ([]PathType, error)
List returns (path, type) for every concept under prefix. An empty prefix is all.
func (*ConceptStore) Page ¶
func (cs *ConceptStore) Page(ctx context.Context, tenant *uuid.UUID, prefix string, limit, offset int) (page []Summary, total int, err error)
Page returns a path-ordered page under prefix and its total, in one transaction. nil mixes tenants.
func (*ConceptStore) PoolSize ¶
func (cs *ConceptStore) PoolSize() int
PoolSize is the most connections the store holds at once.
func (*ConceptStore) Read ¶
func (cs *ConceptStore) Read(ctx context.Context, tenant uuid.UUID, path string) (*okf.Concept, error)
Read returns the whole concept, body included. nil means no such path.
func (*ConceptStore) ReadAll ¶
ReadAll returns every concept, body included, path-ordered, from one snapshot.
func (*ConceptStore) ReadWithBacklinks ¶
func (cs *ConceptStore) ReadWithBacklinks(ctx context.Context, tenant uuid.UUID, path string) (c *okf.Concept, backlinks []string, err error)
ReadWithBacklinks returns the concept and the paths linking to it. nil means no such path.
func (*ConceptStore) Revisions ¶
func (cs *ConceptStore) Revisions(ctx context.Context, tenant uuid.UUID, limit int) ([]Revision, error)
Revisions returns the newest limit revisions, oldest first.
func (*ConceptStore) Search ¶
func (cs *ConceptStore) Search(ctx context.Context, tenant uuid.UUID, query string, limit int, prefix *string) ([]Hit, error)
Search returns ranked cards, never bodies. An empty result beats an invalid tsquery.
func (*ConceptStore) Tenants ¶
func (cs *ConceptStore) Tenants(ctx context.Context) ([]TenantCount, error)
Tenants lists every tenant with concepts, and how many; there is no other tenant registry.
func (*ConceptStore) Update ¶
func (cs *ConceptStore) Update(ctx context.Context, tenant uuid.UUID, c okf.Concept, actor string, expected *int) (version int, conflict *Conflict, err error)
Update writes a concept, as a compare-and-swap unless expected is nil. err is a *NotFoundError for a missing path.
type DailyWrite ¶
DailyWrite is one day's concept-revision count.
type GrepError ¶
type GrepError struct{ Msg string }
GrepError reports a pattern Postgres could not compile or match within the timeout.
type MisconfiguredDatabase ¶
type MisconfiguredDatabase struct{ Msg string }
MisconfiguredDatabase is raised at startup. Crashing loudly beats serving cross-tenant reads.
func (*MisconfiguredDatabase) Error ¶
func (e *MisconfiguredDatabase) Error() string
type NotFoundError ¶
type NotFoundError struct{ Path string }
NotFoundError is ErrNotFound for one path.
func (*NotFoundError) Error ¶
func (e *NotFoundError) Error() string
func (*NotFoundError) Is ¶
func (e *NotFoundError) Is(target error) bool
type Revision ¶
type Revision struct {
Path string
Version int
Op string
UpdatedBy string
CreatedAt time.Time
TenantID uuid.UUID
// Day is CreatedAt's date in the session TimeZone, as psycopg dates it.
Day string
}
Revision is one entry in the revision log, without the snapshot that holds the body.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store owns the pool and sets the tenant GUC, ported from 8f2af2e:src/keepsake/store/pool.py.
func OpenVerified ¶
OpenVerified opens the store and refuses it unless Verify passes.
func (*Store) AdminScope ¶
AdminScope yields a read-only connection reading every tenant; authentication happens above it.
func (*Store) Healthy ¶
Healthy reports whether the pool can hand out a working connection; it never raises.
type Summary ¶
type Summary struct {
Path string
Type string
Title string
Description string
Version int
UpdatedAt time.Time
TenantID uuid.UUID
}
Summary is a concept table row: Hit without the score, plus TenantID for mixed-tenant pages.
type TenantCount ¶
TenantCount is one tenant and how many concepts it holds.