sqlite

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open

func Open(ctx context.Context, path string) (*sql.DB, error)

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

func OpenVaultIndexIn(ctx context.Context, dir string) (store.VaultIndex, error)

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

func (j *ApplyJournal) ListUnapplied(ctx context.Context) ([]store.ApplyUnit, error)

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

func (j *ApplyJournal) PutUnit(ctx context.Context, unit store.ApplyUnit) error

PutUnit writes a new unit with applied=false.

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

func NewDocStore(db *sql.DB) *DocStore

NewDocStore returns a DocStore over a database Open returned.

func (*DocStore) Append

func (d *DocStore) Append(ctx context.Context, docID string, data []byte) (int64, error)

func (*DocStore) Compact

func (d *DocStore) Compact(ctx context.Context, docID string, snapshot []byte, upTo int64) error

Compact ignores a compaction older than the stored one, whose snapshot lacks chunks that are already gone.

func (*DocStore) Create

func (d *DocStore) Create(ctx context.Context, kind, id, docID string, snapshot []byte) (string, bool, error)

func (*DocStore) DocumentFor

func (d *DocStore) DocumentFor(ctx context.Context, kind, id string) (string, error)

func (*DocStore) Load

func (d *DocStore) Load(ctx context.Context, docID string) ([]byte, []store.Chunk, error)

func (*DocStore) ManifestFor

func (d *DocStore) ManifestFor(ctx context.Context, docID string) (string, string, error)

func (*DocStore) Since

func (d *DocStore) Since(ctx context.Context, docID string, after int64) ([]store.Chunk, error)

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

func (m *ManifestStore) Counts(ctx context.Context) (map[string]int, error)

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

func (m *ManifestStore) GetCurrent(ctx context.Context, kind, id string) (store.Version, bool, error)

func (*ManifestStore) GetVersion

func (m *ManifestStore) GetVersion(ctx context.Context, kind, id string, number int) (store.Version, bool, error)

func (*ManifestStore) GetWorking

func (m *ManifestStore) GetWorking(ctx context.Context, kind, id string) ([]byte, bool, error)

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

func (m *ManifestStore) ListAllVersions(ctx context.Context, limit int, cursor string) ([]store.Version, string, error)

func (*ManifestStore) ListExcluded

func (m *ManifestStore) ListExcluded(ctx context.Context) ([]store.Exclusion, error)

ListExcluded returns every excluded manifest, newest first.

func (*ManifestStore) ListIDs

func (m *ManifestStore) ListIDs(ctx context.Context, kind string) ([]string, error)

func (*ManifestStore) ListReferencedBy

func (m *ManifestStore) ListReferencedBy(ctx context.Context, fromKind, fromID string) ([]store.Ref, error)

func (*ManifestStore) ListReferencing

func (m *ManifestStore) ListReferencing(ctx context.Context, toKind, toID string) ([]store.Summary, error)

func (*ManifestStore) ListSummaries

func (m *ManifestStore) ListSummaries(ctx context.Context, kind, query string, refs []store.RefFilter) ([]store.Summary, error)

func (*ManifestStore) ListVersions

func (m *ManifestStore) ListVersions(ctx context.Context, kind, id string) ([]store.Version, error)

func (*ManifestStore) PutVersion

func (m *ManifestStore) PutVersion(ctx context.Context, v store.Version) error

func (*ManifestStore) PutWorking

func (m *ManifestStore) PutWorking(ctx context.Context, kind, id string, yamlBytes []byte) error

PutWorking stores a manifest's working copy (autosave without versioning).

func (*ManifestStore) Recover

func (m *ManifestStore) Recover(ctx context.Context, kind, id, reason, operator string) error

Recover deletes an exclusion record.

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

func (v *VaultIndex) Close() error

Close closes the underlying 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

func (v *VaultIndex) GetFileHash(ctx context.Context, kind, id string) (string, bool, error)

GetFileHash returns the SHA-256 last recorded for kind/id, if any.

func (*VaultIndex) GetMeta

func (v *VaultIndex) GetMeta(ctx context.Context, key string) (string, bool, error)

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.

func (*VaultIndex) PutMeta

func (v *VaultIndex) PutMeta(ctx context.Context, key, value string) error

PutMeta upserts one fact about the index itself.

Jump to

Keyboard shortcuts

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