store

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 20 Imported by: 0

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

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

View Source
const AdminPolicy = "admin_read"

AdminPolicy is the one policy the startup check exempts from reading TenantGUC.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound reports that a path has no concept in the tenant's scope.

Functions

func IsUnavailable

func IsUnavailable(err error) bool

IsUnavailable reports whether err means the database is down, as 2de90d2:src/keepsake/server/tools.py reads OperationalError.

func PoolSize

func PoolSize() (int, error)

PoolSize reads KEEPSAKE_POOL_SIZE, defaulting to 10, and refuses a bad value with a sentence.

func Schema

func Schema() (string, error)

Schema reads KEEPSAKE_SCHEMA, defaulting to "okf" only when it is unset.

func SetAcquireTimeout

func SetAcquireTimeout(d time.Duration) func()

SetAcquireTimeout overrides acquireTimeout for a test and returns a restorer.

func ValidatedSchema

func ValidatedSchema(name string) (string, error)

ValidatedSchema rejects anything not a bare identifier: the name is formatted into DDL.

func Verify

func Verify(ctx context.Context, s *Store, schema string) error

Verify raises unless row-level security actually constrains the connected role.

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

func (cs *ConceptStore) Graph(ctx context.Context, tenant uuid.UUID, limit int) ([]GraphRow, error)

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

func (cs *ConceptStore) ReadAll(ctx context.Context, tenant uuid.UUID) ([]okf.Concept, error)

ReadAll returns every concept, body included, path-ordered, from one snapshot.

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 query.

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

func (cs *ConceptStore) Totals(ctx context.Context, tenant *uuid.UUID) (Totals, error)

Totals are corpus-wide counts for the admin console's summary tiles.

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 Conflict

type Conflict struct {
	CurrentVersion int
	CurrentBody    string
}

Conflict is a stale expected version. CurrentBody is the text to merge against.

type DailyWrite

type DailyWrite struct {
	Date  time.Time
	Count int
}

DailyWrite is one day's concept-revision count.

type GraphRow

type GraphRow struct {
	Path  string
	Type  string
	Title string
	Links []string
}

GraphRow is (path, type, title, links) for one concept, as Graph returns.

type GrepError

type GrepError struct{ Msg string }

GrepError reports a pattern Postgres could not compile or match within the timeout.

func (*GrepError) Error

func (e *GrepError) Error() string

type GrepHit

type GrepHit struct {
	Path    string
	Snippet string
}

GrepHit is one (path, snippet) match; the snippet is a card, not a body.

type Hit

type Hit struct {
	Path        string
	Type        string
	Title       string
	Description string
	Score       float64
}

Hit is one search result. It carries no body: the agent searches, chooses, then reads.

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 PathType

type PathType struct {
	Path string
	Type string
}

PathType is one (path, type) pair, as List returns.

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 Open

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

Open creates the pool for dsn, scoped to schema.

func OpenVerified

func OpenVerified(ctx context.Context, dsn, schema string) (*Store, error)

OpenVerified opens the store and refuses it unless Verify passes.

func (*Store) AdminScope

func (s *Store) AdminScope(ctx context.Context, fn func(pgx.Tx) error) error

AdminScope yields a read-only connection reading every tenant; authentication happens above it.

func (*Store) Close

func (s *Store) Close()

Close releases the pool's connections.

func (*Store) Healthy

func (s *Store) Healthy(ctx context.Context) bool

Healthy reports whether the pool can hand out a working connection; it never raises.

func (*Store) Raw

func (s *Store) Raw(ctx context.Context, fn func(pgx.Tx) error) error

Raw yields a read-only connection with no tenant scope, for startup checks only.

func (*Store) Scope

func (s *Store) Scope(ctx context.Context, tenant uuid.UUID, fn func(pgx.Tx) error) error

Scope yields a connection scoped to tenant for the life of one transaction.

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

type TenantCount struct {
	TenantID uuid.UUID
	Count    int
}

TenantCount is one tenant and how many concepts it holds.

type Totals

type Totals struct {
	Concepts  int
	ByType    map[string]int
	Revisions int
	Links     int
	Orphans   int
}

Totals are corpus-wide counts for the admin console's summary tiles.

Jump to

Keyboard shortcuts

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