Documentation
¶
Overview ¶
Package store opens the team database and scopes every query to the authenticated user. It supports two dialects:
- PostgreSQL (team mode): row-level security is the isolation backstop. Two roles are involved — the MIGRATION role (table owner) applies schema and policies (owners bypass RLS, which the SECURITY DEFINER membership helpers rely on), and the APPLICATION role (non-owner, default "omniagent_app") the running server connects as; ENABLE ROW LEVEL SECURITY binds every policy for it. Application queries run inside AsUser or AsSystem, which set the transaction-local GUCs the policies read.
- SQLite (personal mode): a single implicit user, so there is nothing to isolate. The RLS function/policy/grant migrations are skipped and AsUser/AsSystem are pass-throughs — the same service layer runs against both dialects unchanged.
The raw database handle is unexported so no query path can bypass scoping.
Index ¶
Constants ¶
View Source
const DefaultAppRole = "omniagent_app"
DefaultAppRole is the non-owner role the application connects as.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// AppDSN is the application connection string (non-owner role).
AppDSN string
// MigrateDSN is the owner connection string used only by Migrate.
// Empty falls back to AppDSN with a warning — acceptable for dev,
// wrong for production (the app role must not own tables).
MigrateDSN string
// AppRole is the application role name granted table access by the
// migrations. Defaults to DefaultAppRole.
AppRole string
// Logger defaults to slog.Default().
Logger *slog.Logger
}
Config configures the team store.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the dialect-aware, scoped team database handle.
func (*Store) AsSystem ¶
AsSystem runs fn inside a transaction with the system (auth layer / agent) context: full access to auth tables and agent message inserts, per policy. Use only from the auth layer and agent plumbing — never for user requests.
Click to show internal directories.
Click to hide internal directories.