Documentation
¶
Overview ¶
Package sqlite is the SQLite adapter for both store.ManifestStore and store.OperationalStore, backed by modernc.org/sqlite (a pure-Go driver, no cgo). Schema migrations are embedded and applied on Open.
Index ¶
- func Open(ctx context.Context, path string) (*sql.DB, error)
- func OpenVaultIndexIn(ctx context.Context, dir string) (store.VaultIndex, error)
- type AccessStore
- func (s *AccessStore) DeletePerson(ctx context.Context, email string) error
- func (s *AccessStore) GetAgentGrant(ctx context.Context, id string) (store.AgentGrant, error)
- func (s *AccessStore) GetPerson(ctx context.Context, email string) (store.Person, error)
- func (s *AccessStore) GrantPerson(ctx context.Context, p store.Person) (store.Person, error)
- func (s *AccessStore) ListAgentGrants(ctx context.Context, email string) ([]store.AgentGrant, error)
- func (s *AccessStore) ListPeople(ctx context.Context) ([]store.Person, error)
- func (s *AccessStore) PutAgentGrant(ctx context.Context, t store.AgentGrant) error
- func (s *AccessStore) RecordSignIn(ctx context.Context, in store.SignIn) (store.Person, error)
- func (s *AccessStore) RevokeAgentGrant(ctx context.Context, id string, at time.Time) error
- func (s *AccessStore) RotateAgentGrant(ctx context.Context, id string, from int) (bool, error)
- func (s *AccessStore) TouchAgentGrant(ctx context.Context, id string, at time.Time) error
- type ApplyJournal
- func (j *ApplyJournal) ListUnapplied(ctx context.Context) ([]store.ApplyUnit, error)
- func (j *ApplyJournal) MarkApplied(ctx context.Context, unitID string) error
- func (j *ApplyJournal) PruneOld(ctx context.Context, keepCount int) error
- func (j *ApplyJournal) PutUnit(ctx context.Context, unit store.ApplyUnit) error
- func (j *ApplyJournal) WithinTransaction(ctx context.Context, fn func(ctx context.Context, tx store.ApplyJournal) error) error
- type DocStore
- func (d *DocStore) Append(ctx context.Context, docID string, data []byte) (int64, error)
- func (d *DocStore) Compact(ctx context.Context, docID string, snapshot []byte, upTo int64) error
- func (d *DocStore) Create(ctx context.Context, kind, id, docID string, snapshot []byte) (string, bool, error)
- func (d *DocStore) DocumentFor(ctx context.Context, kind, id string) (string, error)
- func (d *DocStore) Load(ctx context.Context, docID string) ([]byte, []store.Chunk, error)
- func (d *DocStore) ManifestFor(ctx context.Context, docID string) (string, string, error)
- func (d *DocStore) Since(ctx context.Context, docID string, after int64) ([]store.Chunk, error)
- type ManifestStore
- func (m *ManifestStore) Counts(ctx context.Context) (map[string]int, error)
- func (m *ManifestStore) CurrentMany(ctx context.Context, kind string, ids []string) ([]store.Version, error)
- func (m *ManifestStore) CurrentOfKind(ctx context.Context, kind string) ([]store.Version, error)
- func (m *ManifestStore) DecideProposal(ctx context.Context, id, status, by, reason string, at time.Time, version int) (store.Proposal, error)
- func (m *ManifestStore) DecideProposalSet(ctx context.Context, set, status, by, reason string, at time.Time, ...) ([]store.Proposal, error)
- func (m *ManifestStore) DeleteChangeItem(ctx context.Context, set, kind, id string) error
- func (m *ManifestStore) Events(ctx context.Context, after int64, limit int) ([]store.Event, error)
- func (m *ManifestStore) Exclude(ctx context.Context, kind, id, name, reason, operator string) error
- func (m *ManifestStore) GetChangeItem(ctx context.Context, set, kind, id string) (store.ChangeItem, bool, error)
- func (m *ManifestStore) GetChangeSet(ctx context.Context, id string) (store.ChangeSet, error)
- func (m *ManifestStore) GetCurrent(ctx context.Context, kind, id string) (store.Version, bool, error)
- func (m *ManifestStore) GetProposal(ctx context.Context, id string) (store.Proposal, error)
- func (m *ManifestStore) GetVersion(ctx context.Context, kind, id string, number int) (store.Version, bool, error)
- func (m *ManifestStore) GetWorking(ctx context.Context, kind, id string) ([]byte, bool, error)
- func (m *ManifestStore) IndexReferences(ctx context.Context, fromKind, fromID string, refs []store.Ref) error
- func (m *ManifestStore) LatestNumber(ctx context.Context, kind, id string) (int, error)
- func (m *ManifestStore) ListAllVersions(ctx context.Context, limit int, cursor string) ([]store.Version, string, error)
- func (m *ManifestStore) ListChangeItems(ctx context.Context, set string) ([]store.ChangeItem, error)
- func (m *ManifestStore) ListChangeSets(ctx context.Context, f store.ChangeSetFilter) ([]store.ChangeSet, error)
- func (m *ManifestStore) ListExcluded(ctx context.Context) ([]store.Exclusion, error)
- func (m *ManifestStore) ListIDs(ctx context.Context, kind string) ([]string, error)
- func (m *ManifestStore) ListProposals(ctx context.Context, f store.ProposalFilter) ([]store.Proposal, error)
- func (m *ManifestStore) ListReferencedBy(ctx context.Context, fromKind, fromID string) ([]store.Ref, error)
- func (m *ManifestStore) ListReferencing(ctx context.Context, toKind, toID string) ([]store.Summary, error)
- func (m *ManifestStore) ListSummaries(ctx context.Context, kind, query string, refs []store.RefFilter) ([]store.Summary, error)
- func (m *ManifestStore) ListVersions(ctx context.Context, kind, id string) ([]store.Version, error)
- func (m *ManifestStore) MoveChangeSet(ctx context.Context, id, from, to, by, reason string, at time.Time) (store.ChangeSet, error)
- func (m *ManifestStore) PutChangeItem(ctx context.Context, it store.ChangeItem) error
- func (m *ManifestStore) PutChangeSet(ctx context.Context, cs store.ChangeSet) error
- func (m *ManifestStore) PutProposal(ctx context.Context, p store.Proposal) error
- func (m *ManifestStore) PutVersion(ctx context.Context, v store.Version) error
- func (m *ManifestStore) PutWorking(ctx context.Context, kind, id string, yamlBytes []byte) error
- func (m *ManifestStore) RecordSeries(ctx context.Context, items []store.SeriesItem) error
- func (m *ManifestStore) Recover(ctx context.Context, kind, id, reason, operator string) error
- func (m *ManifestStore) ReferencingKind(ctx context.Context, toKind string) (map[string][]store.Summary, error)
- func (m *ManifestStore) SeriesAsOf(ctx context.Context, kind, series string, ids []string, at time.Time) (map[string][]store.SeriesItem, error)
- func (m *ManifestStore) WithinTransaction(ctx context.Context, ...) error
- type OperationalStore
- func (o *OperationalStore) CurrentStates(ctx context.Context, projectIDs []string) (map[string]string, error)
- func (o *OperationalStore) ListProjectStateHistory(ctx context.Context, projectID string) ([]store.ProjectStateEntry, error)
- func (o *OperationalStore) PutProjectStateTransition(ctx context.Context, e store.ProjectStateEntry) error
- type VaultIndex
- func (v *VaultIndex) Access() store.AccessStore
- func (v *VaultIndex) Close() error
- func (v *VaultIndex) DeleteFileHash(ctx context.Context, kind, id string) error
- func (v *VaultIndex) Docs() store.DocStore
- func (v *VaultIndex) GetFileHash(ctx context.Context, kind, id string) (string, bool, error)
- func (v *VaultIndex) GetMeta(ctx context.Context, key string) (string, bool, error)
- func (v *VaultIndex) Journal() store.ApplyJournal
- func (v *VaultIndex) Operational() store.OperationalStore
- func (v *VaultIndex) PutFileHash(ctx context.Context, kind, id, sha256, mtime string) error
- func (v *VaultIndex) PutMeta(ctx context.Context, key, value string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Open ¶
Open opens (creating if needed) a SQLite database at path, applies any migration not yet recorded, and returns the shared *sql.DB. Callers build ManifestStore and OperationalStore from it with NewManifestStore and NewOperationalStore.
func OpenVaultIndexIn ¶
OpenVaultIndexIn opens the index a vault keeps in dir, as dir/index.sqlite. Its type is vault.Options.OpenIndex, so the composition root hands it to a vault without either adapter importing the other.
Types ¶
type AccessStore ¶ added in v2.2.0
type AccessStore struct {
// contains filtered or unexported fields
}
AccessStore is the SQLite adapter for store.AccessStore. Each method is one statement, and the database has one connection, so each is atomic.
func NewAccessStore ¶ added in v2.2.0
func NewAccessStore(db *sql.DB) *AccessStore
NewAccessStore returns an AccessStore over a database Open returned.
func (*AccessStore) DeletePerson ¶ added in v2.2.0
func (s *AccessStore) DeletePerson(ctx context.Context, email string) error
func (*AccessStore) GetAgentGrant ¶ added in v2.5.0
func (s *AccessStore) GetAgentGrant(ctx context.Context, id string) (store.AgentGrant, error)
func (*AccessStore) GrantPerson ¶ added in v2.2.0
func (*AccessStore) ListAgentGrants ¶ added in v2.5.0
func (s *AccessStore) ListAgentGrants(ctx context.Context, email string) ([]store.AgentGrant, error)
func (*AccessStore) ListPeople ¶ added in v2.2.0
func (*AccessStore) PutAgentGrant ¶ added in v2.5.0
func (s *AccessStore) PutAgentGrant(ctx context.Context, t store.AgentGrant) error
func (*AccessStore) RecordSignIn ¶ added in v2.2.0
func (*AccessStore) RevokeAgentGrant ¶ added in v2.5.0
func (*AccessStore) RotateAgentGrant ¶ added in v2.5.0
func (*AccessStore) TouchAgentGrant ¶ added in v2.5.0
type ApplyJournal ¶
type ApplyJournal struct {
// contains filtered or unexported fields
}
ApplyJournal is the SQLite adapter for store.ApplyJournal. It wraps both *sql.DB and *sql.Tx through the executor interface.
func NewApplyJournal ¶
func NewApplyJournal(db *sql.DB) *ApplyJournal
NewApplyJournal creates a new ApplyJournal over the given database.
func (*ApplyJournal) ListUnapplied ¶
ListUnapplied returns every unit with applied=false, oldest first.
func (*ApplyJournal) MarkApplied ¶
func (j *ApplyJournal) MarkApplied(ctx context.Context, unitID string) error
MarkApplied marks a unit as applied.
func (*ApplyJournal) PruneOld ¶
func (j *ApplyJournal) PruneOld(ctx context.Context, keepCount int) error
PruneOld removes applied units older than keepCount (keeps the most recent). A keepCount of 0 or less means unlimited (no pruning).
func (*ApplyJournal) WithinTransaction ¶
func (j *ApplyJournal) WithinTransaction(ctx context.Context, fn func(ctx context.Context, tx store.ApplyJournal) error) error
WithinTransaction runs fn in a transaction.
type DocStore ¶
type DocStore struct {
// contains filtered or unexported fields
}
DocStore is the SQLite adapter for store.DocStore, in the same database as the rest of the index. The database has one connection, so every transaction here runs alone, which is what makes Create and Append atomic.
func NewDocStore ¶
NewDocStore returns a DocStore over a database Open returned.
func (*DocStore) Compact ¶
Compact ignores a compaction older than the stored one, whose snapshot lacks chunks that are already gone.
func (*DocStore) DocumentFor ¶
func (*DocStore) ManifestFor ¶
type ManifestStore ¶
type ManifestStore struct {
// contains filtered or unexported fields
}
ManifestStore is the SQLite adapter for store.ManifestStore. The zero value is not usable; construct with NewManifestStore.
func NewManifestStore ¶
func NewManifestStore(db *sql.DB) *ManifestStore
func (*ManifestStore) CurrentMany ¶ added in v2.3.0
func (m *ManifestStore) CurrentMany(ctx context.Context, kind string, ids []string) ([]store.Version, error)
CurrentMany returns the current version of each of ids that exists.
func (*ManifestStore) CurrentOfKind ¶ added in v2.3.0
CurrentOfKind returns, in one query, what GetCurrent returns for every manifest of a kind: the working copy where there is one, else the highest version.
func (*ManifestStore) DecideProposal ¶ added in v2.5.0
func (m *ManifestStore) DecideProposal(ctx context.Context, id, status, by, reason string, at time.Time, version int) (store.Proposal, error)
DecideProposal decides an open proposal, in one statement.
func (*ManifestStore) DecideProposalSet ¶ added in v2.6.0
func (m *ManifestStore) DecideProposalSet(ctx context.Context, set, status, by, reason string, at time.Time, versions map[string]int) ([]store.Proposal, error)
DecideProposalSet decides every proposal of a set in one transaction: all of them, or none when any is decided already.
func (*ManifestStore) DeleteChangeItem ¶ added in v2.7.0
func (m *ManifestStore) DeleteChangeItem(ctx context.Context, set, kind, id string) error
DeleteChangeItem drops an item.
func (*ManifestStore) Exclude ¶
func (m *ManifestStore) Exclude(ctx context.Context, kind, id, name, reason, operator string) error
Exclude records an exclusion for a manifest.
func (*ManifestStore) GetChangeItem ¶ added in v2.7.0
func (m *ManifestStore) GetChangeItem(ctx context.Context, set, kind, id string) (store.ChangeItem, bool, error)
GetChangeItem returns one item.
func (*ManifestStore) GetChangeSet ¶ added in v2.7.0
GetChangeSet returns one change set.
func (*ManifestStore) GetCurrent ¶
func (*ManifestStore) GetProposal ¶ added in v2.5.0
GetProposal returns one proposal.
func (*ManifestStore) GetVersion ¶
func (*ManifestStore) GetWorking ¶
GetWorking returns a manifest's working copy (autosave without versioning). Returns found=false when none exists.
func (*ManifestStore) IndexReferences ¶
func (m *ManifestStore) IndexReferences(ctx context.Context, fromKind, fromID string, refs []store.Ref) error
IndexReferences replaces every recorded outgoing reference for fromKind/fromID with refs.
func (*ManifestStore) LatestNumber ¶ added in v2.3.0
LatestNumber returns the highest version number, 0 when there is none.
func (*ManifestStore) ListAllVersions ¶
func (*ManifestStore) ListChangeItems ¶ added in v2.7.0
func (m *ManifestStore) ListChangeItems(ctx context.Context, set string) ([]store.ChangeItem, error)
ListChangeItems returns a change set's items, oldest first.
func (*ManifestStore) ListChangeSets ¶ added in v2.7.0
func (m *ManifestStore) ListChangeSets(ctx context.Context, f store.ChangeSetFilter) ([]store.ChangeSet, error)
ListChangeSets returns change sets, newest first.
func (*ManifestStore) ListExcluded ¶
ListExcluded returns every excluded manifest, newest first.
func (*ManifestStore) ListProposals ¶ added in v2.5.0
func (m *ManifestStore) ListProposals(ctx context.Context, f store.ProposalFilter) ([]store.Proposal, error)
ListProposals returns proposals, newest first.
func (*ManifestStore) ListReferencedBy ¶
func (*ManifestStore) ListReferencing ¶
func (*ManifestStore) ListSummaries ¶
func (*ManifestStore) ListVersions ¶
func (*ManifestStore) MoveChangeSet ¶ added in v2.7.0
func (m *ManifestStore) MoveChangeSet(ctx context.Context, id, from, to, by, reason string, at time.Time) (store.ChangeSet, error)
MoveChangeSet moves a change set from one status to another.
func (*ManifestStore) PutChangeItem ¶ added in v2.7.0
func (m *ManifestStore) PutChangeItem(ctx context.Context, it store.ChangeItem) error
PutChangeItem keeps an item.
func (*ManifestStore) PutChangeSet ¶ added in v2.7.0
PutChangeSet keeps a change set.
func (*ManifestStore) PutProposal ¶ added in v2.5.0
PutProposal keeps a proposal.
func (*ManifestStore) PutVersion ¶
func (*ManifestStore) PutWorking ¶
PutWorking stores a manifest's working copy (autosave without versioning).
func (*ManifestStore) RecordSeries ¶ added in v2.3.0
func (m *ManifestStore) RecordSeries(ctx context.Context, items []store.SeriesItem) error
RecordSeries appends series items.
func (*ManifestStore) Recover ¶
func (m *ManifestStore) Recover(ctx context.Context, kind, id, reason, operator string) error
Recover deletes an exclusion record.
func (*ManifestStore) ReferencingKind ¶ added in v2.3.0
func (m *ManifestStore) ReferencingKind(ctx context.Context, toKind string) (map[string][]store.Summary, error)
ReferencingKind returns, in one query, who references each manifest of toKind: ListReferencing for all of them at once.
func (*ManifestStore) SeriesAsOf ¶ added in v2.3.0
func (m *ManifestStore) SeriesAsOf(ctx context.Context, kind, series string, ids []string, at time.Time) (map[string][]store.SeriesItem, error)
SeriesAsOf merges each key's rows into its value at at: the last row recorded by then.
func (*ManifestStore) WithinTransaction ¶
func (m *ManifestStore) WithinTransaction(ctx context.Context, fn func(ctx context.Context, tx store.ManifestStore) error) error
type OperationalStore ¶
type OperationalStore struct {
// contains filtered or unexported fields
}
OperationalStore is the SQLite adapter for store.OperationalStore.
func NewOperationalStore ¶
func NewOperationalStore(db *sql.DB) *OperationalStore
func (*OperationalStore) CurrentStates ¶ added in v2.3.0
func (o *OperationalStore) CurrentStates(ctx context.Context, projectIDs []string) (map[string]string, error)
CurrentStates returns the latest state of each project with history, a query per thousand projects, inside SQLite's limit on parameters.
func (*OperationalStore) ListProjectStateHistory ¶
func (o *OperationalStore) ListProjectStateHistory(ctx context.Context, projectID string) ([]store.ProjectStateEntry, error)
func (*OperationalStore) PutProjectStateTransition ¶
func (o *OperationalStore) PutProjectStateTransition(ctx context.Context, e store.ProjectStateEntry) error
type VaultIndex ¶
type VaultIndex struct {
*ManifestStore
// contains filtered or unexported fields
}
VaultIndex is the SQLite adapter for store.VaultIndex: everything the vault keeps beside its files, in one database. It wraps a ManifestStore, an ApplyJournal, an OperationalStore and a DocStore over the same *sql.DB, and adds the file-hash and meta tables (vault_files, vault_meta) that used to be raw SQL inside the vault package itself.
func NewVaultIndex ¶
func NewVaultIndex(db *sql.DB) *VaultIndex
NewVaultIndex builds a VaultIndex over an already-open, already-migrated database.
func OpenVaultIndex ¶
func OpenVaultIndex(ctx context.Context, path string) (*VaultIndex, error)
OpenVaultIndex opens (creating if needed) a SQLite database at path, applies migrations, and returns a VaultIndex over it.
func (*VaultIndex) Access ¶ added in v2.2.0
func (v *VaultIndex) Access() store.AccessStore
Access returns the access list over the same database.
func (*VaultIndex) DeleteFileHash ¶
func (v *VaultIndex) DeleteFileHash(ctx context.Context, kind, id string) error
DeleteFileHash removes a file's recorded hash, if any.
func (*VaultIndex) Docs ¶
func (v *VaultIndex) Docs() store.DocStore
Docs returns the shared drafts' documents over the same database.
func (*VaultIndex) GetFileHash ¶
GetFileHash returns the SHA-256 last recorded for kind/id, if any.
func (*VaultIndex) GetMeta ¶
GetMeta returns one recorded fact about the index itself (for example the vault.yaml hash recorded at the last open, under key "vault.yaml.hash"). Both that key and the rebuild-time key the vault used to keep in a separate index_meta table live in vault_meta now: nothing but this method ever reads or writes either.
func (*VaultIndex) Journal ¶
func (v *VaultIndex) Journal() store.ApplyJournal
Journal returns the apply journal over the same database.
func (*VaultIndex) Operational ¶
func (v *VaultIndex) Operational() store.OperationalStore
Operational returns the project-state store over the same database.
func (*VaultIndex) PutFileHash ¶
func (v *VaultIndex) PutFileHash(ctx context.Context, kind, id, sha256, mtime string) error
PutFileHash upserts a file's hash and mtime.