Documentation
¶
Overview ¶
Package database provides SQLite-backed storage for servers, manifests, and approval records. Manifest content is append-only: the only mutation ever performed on an existing manifest row is a state transition — see Store.UpdateManifestState.
Index ¶
- Constants
- Variables
- type Approval
- type ManifestRecord
- type SQLiteStore
- func (s *SQLiteStore) Close() error
- func (q SQLiteStore) CreateServer(ctx context.Context, name, endpoint string) (*Server, error)
- func (q SQLiteStore) GetApprovedManifest(ctx context.Context, serverID int64) (*ManifestRecord, error)
- func (q SQLiteStore) GetManifestByHash(ctx context.Context, serverID int64, hash string) (*ManifestRecord, error)
- func (q SQLiteStore) GetManifestByID(ctx context.Context, id int64) (*ManifestRecord, error)
- func (q SQLiteStore) GetServerByID(ctx context.Context, id int64) (*Server, error)
- func (q SQLiteStore) GetServerByName(ctx context.Context, name string) (*Server, error)
- func (q SQLiteStore) InsertApproval(ctx context.Context, a *Approval) (int64, error)
- func (q SQLiteStore) InsertManifest(ctx context.Context, m *ManifestRecord) (int64, error)
- func (q SQLiteStore) ListApprovalsForManifest(ctx context.Context, manifestID int64) ([]Approval, error)
- func (q SQLiteStore) ListPendingManifests(ctx context.Context) ([]ManifestRecord, error)
- func (q SQLiteStore) ListServers(ctx context.Context) ([]Server, error)
- func (q SQLiteStore) UpdateManifestState(ctx context.Context, id int64, newState string) error
- func (s *SQLiteStore) WithTx(ctx context.Context, fn func(Store) error) error
- type Server
- type Store
Constants ¶
const ( StatePending = "PENDING" StateApproved = "APPROVED" StateRejected = "REJECTED" StateSuperseded = "SUPERSEDED" )
Manifest lifecycle states.
const ( DecisionApproved = "APPROVED" DecisionRejected = "REJECTED" )
Approval decisions.
Variables ¶
var ErrNotFound = errors.New("database: not found")
ErrNotFound is returned by every Store lookup when the row does not exist. There is exactly one absence convention: no lookup returns a nil object with a nil error, so callers use errors.Is rather than a nil check that is easy to forget and fails as a nil dereference when they do.
Functions ¶
This section is empty.
Types ¶
type ManifestRecord ¶
type SQLiteStore ¶
type SQLiteStore struct {
// contains filtered or unexported fields
}
SQLiteStore is the top-level Store implementation backed by a *sql.DB.
func Open ¶
func Open(path string) (*SQLiteStore, error)
Open opens (creating if necessary) a SQLite database at path, applies the schema, and configures WAL journaling and foreign keys. The parent directory is created if it does not exist.
func (*SQLiteStore) Close ¶
func (s *SQLiteStore) Close() error
func (SQLiteStore) CreateServer ¶
func (SQLiteStore) GetApprovedManifest ¶
func (q SQLiteStore) GetApprovedManifest(ctx context.Context, serverID int64) (*ManifestRecord, error)
func (SQLiteStore) GetManifestByHash ¶
func (SQLiteStore) GetManifestByID ¶
func (q SQLiteStore) GetManifestByID(ctx context.Context, id int64) (*ManifestRecord, error)
func (SQLiteStore) GetServerByID ¶
func (SQLiteStore) GetServerByName ¶
func (SQLiteStore) InsertApproval ¶
func (SQLiteStore) InsertManifest ¶
func (q SQLiteStore) InsertManifest(ctx context.Context, m *ManifestRecord) (int64, error)
func (SQLiteStore) ListApprovalsForManifest ¶
func (SQLiteStore) ListPendingManifests ¶
func (q SQLiteStore) ListPendingManifests(ctx context.Context) ([]ManifestRecord, error)
func (SQLiteStore) ListServers ¶
func (SQLiteStore) UpdateManifestState ¶
type Store ¶
type Store interface {
CreateServer(ctx context.Context, name, endpoint string) (*Server, error)
GetServerByName(ctx context.Context, name string) (*Server, error)
GetServerByID(ctx context.Context, id int64) (*Server, error)
ListServers(ctx context.Context) ([]Server, error)
InsertManifest(ctx context.Context, m *ManifestRecord) (int64, error)
GetManifestByHash(ctx context.Context, serverID int64, hash string) (*ManifestRecord, error)
GetManifestByID(ctx context.Context, id int64) (*ManifestRecord, error)
GetApprovedManifest(ctx context.Context, serverID int64) (*ManifestRecord, error)
ListPendingManifests(ctx context.Context) ([]ManifestRecord, error)
UpdateManifestState(ctx context.Context, id int64, newState string) error
InsertApproval(ctx context.Context, a *Approval) (int64, error)
ListApprovalsForManifest(ctx context.Context, manifestID int64) ([]Approval, error)
WithTx(ctx context.Context, fn func(Store) error) error
}
Store is the persistence interface used by the approval workflow and API layers. Lookups return ErrNotFound when the row does not exist; no method returns a nil object with a nil error. Note what is deliberately absent: there is no method that updates a manifest's hash or canonical_json after insert. UpdateManifestState is the only mutation on an existing manifest row, so manifest content is physically immutable once written, not just immutable by convention.