Documentation
¶
Overview ¶
Package dbcontext is the one resolver for "which database and path does this command act on" (decision 0008, spec/features/database-context-navigation REQ:use-sets-scoped-context and REQ:context-lookup).
The client side (CLI, TUI) knows its working directory, so it computes the project root and the walk-up candidates here and sends them; the server stores and reads contexts under <OVDB home>/contexts, keyed by a hash of the canonical directory, and applies the same ladder with Resolve.
Index ¶
- Constants
- func Canonical(dir string) string
- func ChooseNext(ids []string) []envelope.Next
- func ClearDatabase(home, id string) error
- func Key(dir string) string
- func NoContext(ids []string) *envelope.Error
- func Registered(ids []string, id string) (string, bool)
- func Source(c Context) string
- func UnknownDatabase(message, id string, ids []string) *envelope.Error
- func UsingMessage(c Context) string
- type Change
- type Context
- type Document
- type Lookup
- type Request
Constants ¶
const ( ScopeFlag = "flag" // --db ScopeEnvironment = "environment" // OVDB_DATABASE (and OVDB_PATH) ScopeProject = "project" // ovdb use, found by walk-up ScopeGlobal = "global" // ovdb use --global ScopeOnly = "only" // the only registered database )
Rungs of the precedence ladder, as Context.Scope names them.
const ( EnvDatabase = "OVDB_DATABASE" EnvPath = "OVDB_PATH" )
Environment variables of the environment rung.
const (
Dir = "contexts"
)
Locations under OVDB home. Nothing is ever written into a project.
Variables ¶
This section is empty.
Functions ¶
func Canonical ¶
Canonical is dir as an absolute path with symlinks resolved, so the same project reached through a link has one context. A path that cannot be resolved (it no longer exists) is only made absolute and clean.
func ChooseNext ¶
ChooseNext is how to pick a database when none applies.
func ClearDatabase ¶
ClearDatabase removes every stored context naming id, so removing a database never leaves a project pointing at it.
func NoContext ¶
NoContext is not_found for a data command with no database from any rung (AC:no-context-error), listing the registered databases.
func Registered ¶
Registered is the registered id matching id exactly, or the only one that matches ignoring case (ids are unique ignoring case).
func Source ¶
Source names where c came from, for `ovdb use` and `ovdb pwd` (REQ:context-lookup): "project context from /p/a".
func UnknownDatabase ¶
UnknownDatabase is not_found for a database name that is not registered, listing the ones that are.
func UsingMessage ¶
UsingMessage is the line saying what a change set, naming its scope (REQ:use-sets-scoped-context): `Now using todo for this project (/p/a)`.
Types ¶
type Change ¶
type Change struct {
Scope string `json:"scope"` // project or global
Dir string `json:"dir,omitempty"`
Database string `json:"database,omitempty"`
Path string `json:"path,omitempty"`
Clear bool `json:"clear,omitempty"`
}
Change is the body of PUT /api/local/v1/context.
type Context ¶
type Context struct {
Database string `json:"database"`
Path string `json:"path"`
Scope string `json:"scope"`
Dir string `json:"dir,omitempty"`
}
Context is the database and path one command acts on, and where that came from: the rung, and for a project context the directory that supplied it.
type Document ¶
type Document struct {
Schema int `json:"schema"`
// Context is what applies here; null when nothing does.
Context *Context `json:"context"`
// Global is the default for all projects, whatever applies here; the web
// console shows and changes only this one (parity E3).
Global *Context `json:"global"`
// Databases are the registered ids, for choosing one.
Databases []string `json:"databases"`
// Message says what a change did, naming its scope.
Message string `json:"message,omitempty"`
// Notices are one-line warnings, such as a project context skipped
// because its database is no longer registered.
Notices []string `json:"notices,omitempty"`
Next []envelope.Next `json:"next"`
}
Document is the body of GET and PUT /api/local/v1/context and the --json output of `ovdb use` and `ovdb pwd`.
type Lookup ¶
type Lookup struct {
// Dirs runs from the working directory up to the Git working-tree root
// when inside one, otherwise to the top of the file system.
Dirs []string
// Root is the nearest Git working-tree root, or the working directory.
Root string
}
Lookup is where a command runs: the directories to search for a project context, nearest first, and the root `ovdb use` writes to.
type Request ¶
type Request struct {
// Dirs are Lookup.Dirs, nearest first; empty for the web console.
Dirs []string
// Database and Path come from --db or OVDB_DATABASE/OVDB_PATH, with
// Scope ScopeFlag or ScopeEnvironment; empty otherwise.
Database, Path, Scope string
// Root is Lookup.Root, where `ovdb use` stores; never sent.
Root string
}
Request is what a client sends to resolve its context.
func RequestFrom ¶
RequestFrom reads a Request from a query string. Only absolute directories count: the browser, which has no working directory, sends none.