Documentation
¶
Overview ¶
Package sqlite provides Ridu's official embedded SQLite document store.
Index ¶
- func ProjectMigrations(transforms ...ridumigration.DataTransform) ridumigration.ProjectDriver
- func VerifyArtifacts(ctx context.Context, directory string, ...) error
- type Config
- type CreatedArtifact
- type MigrationPhaseStatus
- type MigrationStatus
- type MigrationStepStatus
- type SafetyError
- type Store
- func (backend *Store) AcquireDocumentLock(ctx context.Context, candidate store.DocumentLock, now time.Time, ...) (store.DocumentLock, bool, error)
- func (backend *Store) AllowAuthAttempt(ctx context.Context, keyHash string, now time.Time, window time.Duration, ...) (bool, error)
- func (backend *Store) ApplyArtifacts(ctx context.Context, directory string, ...) error
- func (backend *Store) ArtifactPlan(ctx context.Context, directory string, executableManifest schema.Manifest) ([]MigrationStatus, error)
- func (backend *Store) ArtifactStatus(ctx context.Context, directory string, executableManifest schema.Manifest) ([]MigrationStatus, error)
- func (backend *Store) Begin(ctx context.Context) (store.Transaction, error)
- func (backend *Store) BeginSnapshot(ctx context.Context) (store.Transaction, error)
- func (backend *Store) CancelTask(ctx context.Context, id string) error
- func (backend *Store) ChangePasswordHash(ctx context.Context, collection schema.Collection, userID string, ...) error
- func (backend *Store) ClaimTasks(ctx context.Context, request store.TaskClaim) ([]store.Task, error)
- func (backend *Store) Close() error
- func (backend *Store) CompleteTask(ctx context.Context, id, leaseToken string, output json.RawMessage) error
- func (backend *Store) CreateAPIKey(ctx context.Context, key store.AuthAPIKey, sessionTokenHash string, ...) error
- func (backend *Store) CreateAuthToken(ctx context.Context, token store.AuthToken) error
- func (backend *Store) CreateSession(ctx context.Context, session store.AuthSession, expectedPasswordHash []byte) error
- func (backend *Store) DeleteAPIKey(ctx context.Context, collectionID schema.StableID, userID, id string) error
- func (backend *Store) DeletePreference(ctx context.Context, collectionID schema.StableID, userID, key string) error
- func (backend *Store) DeletePreferences(ctx context.Context, collectionID schema.StableID, userID string) error
- func (backend *Store) DeleteSession(ctx context.Context, tokenHash string) error
- func (backend *Store) DeleteUserSession(ctx context.Context, collectionID schema.StableID, userID, sessionID string) error
- func (backend *Store) DeleteUserSessions(ctx context.Context, collectionID schema.StableID, userID string) error
- func (backend *Store) DismissTaskForTarget(ctx context.Context, id, slug string, target store.DocumentReference) error
- func (backend *Store) DownArtifacts(ctx context.Context, directory string, ...) error
- func (backend *Store) EnqueueTask(ctx context.Context, task store.Task) (store.Task, error)
- func (backend *Store) FailTask(ctx context.Context, failure store.TaskFailure) error
- func (backend *Store) FindAPIKey(ctx context.Context, id string, now time.Time) (store.AuthAPIKey, error)
- func (backend *Store) FindAuthCredential(ctx context.Context, collection schema.Collection, identity string) (store.AuthCredential, error)
- func (backend *Store) FindDocumentLock(ctx context.Context, collectionID schema.StableID, documentID string, ...) (store.DocumentLock, error)
- func (backend *Store) FindSession(ctx context.Context, tokenHash string, now time.Time) (store.AuthSession, error)
- func (backend *Store) FindTask(ctx context.Context, id string) (store.Task, error)
- func (backend *Store) ForceUnlock(ctx context.Context, collectionID schema.StableID, userID string) error
- func (backend *Store) FreshArtifacts(ctx context.Context, directory string, ...) error
- func (backend *Store) GetPreference(ctx context.Context, collectionID schema.StableID, userID, key string) (store.Preference, error)
- func (backend *Store) HeartbeatTask(ctx context.Context, id, leaseToken string, leaseDuration time.Duration) error
- func (backend *Store) ListAPIKeys(ctx context.Context, collectionID schema.StableID, userID string, ...) ([]store.AuthAPIKey, error)
- func (backend *Store) ListSessions(ctx context.Context, collectionID schema.StableID, userID string, ...) ([]store.AuthSession, error)
- func (backend *Store) ListTasks(ctx context.Context, request store.TaskList) ([]store.Task, error)
- func (backend *Store) LockUploadObjects(ctx context.Context, objectKeys []string) (func(), error)
- func (backend *Store) Migrate(ctx context.Context, manifest schema.Manifest) error
- func (backend *Store) Ping(ctx context.Context) error
- func (backend *Store) PruneExpiredAuth(ctx context.Context, limit int) (store.AuthPruneResult, error)
- func (backend *Store) PruneTasks(ctx context.Context, limit int) (int, error)
- func (backend *Store) Ready(ctx context.Context, manifest schema.Manifest) error
- func (backend *Store) ReadyWithMigrationHistory(ctx context.Context, manifest schema.Manifest, expectedHistoryDigest string) error
- func (backend *Store) RecordFailedLogin(ctx context.Context, collectionID schema.StableID, userID string, ...) (store.AuthCredential, error)
- func (backend *Store) RefreshArtifacts(ctx context.Context, directory string, ...) error
- func (backend *Store) ReleaseDocumentLock(ctx context.Context, collectionID schema.StableID, documentID string, ...) error
- func (backend *Store) ReleaseTask(ctx context.Context, id, leaseToken string, delay time.Duration, ...) error
- func (backend *Store) ResetArtifacts(ctx context.Context, directory string, ...) error
- func (backend *Store) ResetLoginAttempts(ctx context.Context, collectionID schema.StableID, userID string, ...) (bool, error)
- func (backend *Store) ResetPasswordWithToken(ctx context.Context, collectionID schema.StableID, tokenHash string, ...) (string, error)
- func (backend *Store) RotateSession(ctx context.Context, currentHash string, replacement store.AuthSession, ...) error
- func (backend *Store) SetPasswordHash(ctx context.Context, collection schema.Collection, userID string, hash []byte, ...) error
- func (backend *Store) SetPreference(ctx context.Context, preference store.Preference) (store.Preference, error)
- func (backend *Store) TouchAPIKey(ctx context.Context, id string, now time.Time) error
- func (backend *Store) UpgradePasswordHash(ctx context.Context, collection schema.Collection, userID string, ...) error
- func (backend *Store) VerifyEmailWithToken(ctx context.Context, collectionID schema.StableID, tokenHash string, ...) (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ProjectMigrations ¶
func ProjectMigrations(transforms ...ridumigration.DataTransform) ridumigration.ProjectDriver
ProjectMigrations returns the narrow compiled-project driver used when an immutable artifact names application data callbacks. Register it with ridu.WithProjectMigrations even in project-command mode; ordinary server runtime still owns its separate Store factory.
func VerifyArtifacts ¶
func VerifyArtifacts(ctx context.Context, directory string, transforms ...ridumigration.DataTransform) error
VerifyArtifacts replays complete history into an isolated temporary SQLite database and proves that every artifact and the latest manifest are complete.
Types ¶
type Config ¶
type Config struct {
// Path is a filesystem path, a file: SQLite URI, or :memory:.
Path string
// BusyTimeout bounds how long SQLite waits for another writer. Zero selects
// ten seconds. Negative values and values above SQLite's signed 32-bit
// millisecond limit are rejected.
BusyTimeout time.Duration
// DisableWAL keeps file databases in their existing journal mode. WAL is
// enabled by default because it permits readers while the single writer is
// active. SQLite memory databases ignore WAL mode.
DisableWAL bool
// MaxConnections bounds pooled readers. Operation transactions still use
// BEGIN IMMEDIATE and SQLite's single-writer contract.
MaxConnections int
}
Config controls the bounded connection behavior of the embedded SQLite store. Zero values select safe local defaults.
type CreatedArtifact ¶
type CreatedArtifact struct {
Path string `json:"path"`
Name string `json:"name"`
Checksum string `json:"checksum"`
Version uint32 `json:"version"`
}
CreatedArtifact is the stable filesystem identity of one newly committed immutable SQLite migration. It deliberately does not expose Ridu's internal artifact-file representation.
func CreateArtifact ¶
func CreateArtifact(ctx context.Context, directory, name string, after schema.Manifest, now time.Time, allowDestructive bool, transforms ...ridumigration.DataTransformDescriptor) (CreatedArtifact, error)
CreateArtifact plans and atomically creates one immutable SQLite migration file. Existing files are never overwritten and the new artifact must continue the latest committed manifest in directory. The before manifest is derived from that history so applications never need to decode private artifact files themselves.
type MigrationPhaseStatus ¶
type MigrationPhaseStatus struct {
ID string `json:"id"`
Mode ridumigration.PhaseMode `json:"mode"`
State string `json:"state"`
Steps []MigrationStepStatus `json:"steps"`
}
MigrationPhaseStatus reports one transaction phase in an immutable artifact.
type MigrationStatus ¶
type MigrationStatus struct {
Name string `json:"name"`
Checksum string `json:"checksum"`
Version uint32 `json:"version"`
Applied bool `json:"applied"`
Phases []MigrationPhaseStatus `json:"phases"`
}
MigrationStatus describes one immutable SQLite artifact relative to the database ledger. SQLite artifacts are atomic, so phases and steps are either wholly pending or wholly complete and do not need a checkpoint vocabulary.
func InspectArtifacts ¶
func InspectArtifacts(ctx context.Context, path, directory string, executableManifest schema.Manifest) ([]MigrationStatus, error)
InspectArtifacts reports immutable migration state without creating or changing the selected SQLite database. Missing files have an all-pending state; existing files are opened read-only without adapter write pragmas.
type MigrationStepStatus ¶
type MigrationStepStatus struct {
ID string `json:"id"`
Kind ridumigration.StepKind `json:"kind"`
State string `json:"state"`
}
MigrationStepStatus reports one SQLite artifact step.
type SafetyError ¶
type SafetyError struct {
Risks []ridumigration.Risk
}
SafetyError reports a valid SQLite transition that requires explicit destructive approval before an immutable artifact can be created.
func (*SafetyError) Error ¶
func (err *SafetyError) Error() string
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is one embedded SQLite database. Schema changes are explicit through Migrate or immutable artifact application; Open never mutates CMS tables.
func OpenWithConfig ¶
OpenWithConfig connects to SQLite without creating or changing Ridu's schema. Every pooled connection receives the same validated pragmas.
func (*Store) AcquireDocumentLock ¶
func (*Store) AllowAuthAttempt ¶
func (*Store) ApplyArtifacts ¶
func (backend *Store) ApplyArtifacts(ctx context.Context, directory string, transforms ...ridumigration.DataTransform) error
ApplyArtifacts validates the complete committed history before creating a ledger or changing application schema. All pending artifacts and their ledger rows commit under one BEGIN IMMEDIATE writer reservation.
func (*Store) ArtifactPlan ¶
func (backend *Store) ArtifactPlan(ctx context.Context, directory string, executableManifest schema.Manifest) ([]MigrationStatus, error)
ArtifactPlan returns the same manifest-bound immutable SQLite topology as status.
func (*Store) ArtifactStatus ¶
func (backend *Store) ArtifactStatus(ctx context.Context, directory string, executableManifest schema.Manifest) ([]MigrationStatus, error)
ArtifactStatus binds immutable history to the executable schema, then uses that exact history snapshot to report the atomic applied/pending boundary.
func (*Store) Begin ¶
Begin opens a write-capable operation transaction. BEGIN IMMEDIATE obtains SQLite's honest database-level writer reservation before access and relationship checks run, replacing PostgreSQL row locks without pretending SQLite has finer lock semantics.
func (*Store) BeginSnapshot ¶
BeginSnapshot opens a stable deferred read snapshot without reserving the database's single writer. The operation engine uses it for read-only work.
func (*Store) ChangePasswordHash ¶
func (*Store) ClaimTasks ¶
func (*Store) CompleteTask ¶
func (*Store) CreateAPIKey ¶
func (*Store) CreateAuthToken ¶
func (*Store) CreateSession ¶
func (*Store) DeleteAPIKey ¶
func (*Store) DeletePreference ¶
func (*Store) DeletePreferences ¶
func (*Store) DeleteSession ¶
func (*Store) DeleteUserSession ¶
func (*Store) DeleteUserSessions ¶
func (*Store) DismissTaskForTarget ¶
func (*Store) DownArtifacts ¶
func (backend *Store) DownArtifacts(ctx context.Context, directory string, transforms ...ridumigration.DataTransform) error
DownArtifacts rolls back the most recently applied immutable artifact. The artifact file remains committed, so status reports it as pending and a later ApplyArtifacts call can replay it. Registered callbacks are checksum-bound to the artifact. An already-empty database is a no-op.
func (*Store) EnqueueTask ¶
func (*Store) FindAPIKey ¶
func (*Store) FindAuthCredential ¶
func (backend *Store) FindAuthCredential(ctx context.Context, collection schema.Collection, identity string) (store.AuthCredential, error)
func (*Store) FindDocumentLock ¶
func (*Store) FindSession ¶
func (*Store) ForceUnlock ¶
func (*Store) FreshArtifacts ¶
func (backend *Store) FreshArtifacts(ctx context.Context, directory string, transforms ...ridumigration.DataTransform) error
FreshArtifacts drops every non-internal object in the selected SQLite database and replays committed history in one transaction. Callers must put an explicit destructive confirmation in front of this method. Registered up callbacks replay with their committed artifacts.
func (*Store) GetPreference ¶
func (*Store) HeartbeatTask ¶
func (*Store) ListAPIKeys ¶
func (*Store) ListSessions ¶
func (*Store) LockUploadObjects ¶
LockUploadObjects serializes upload admission and cleanup across every process sharing a file database. SQLite memory databases are private to one Store and use the equivalent in-process gate.
func (*Store) Migrate ¶
Migrate atomically installs SQLite's adapter-owned tables and records the exact manifest digest. It is an explicit development/bootstrap operation; Open never calls it and production callers should apply reviewed immutable artifacts once the SQLite artifact runner is configured.
func (*Store) Ping ¶
Ping proves that SQLite can serve a query and that foreign-key enforcement is active on the selected pooled connection.
func (*Store) PruneExpiredAuth ¶
func (backend *Store) PruneExpiredAuth(ctx context.Context, limit int) (store.AuthPruneResult, error)
PruneExpiredAuth removes at most limit records from each expiring auth family. BEGIN IMMEDIATE serializes candidates across processes so two maintenance workers cannot count or delete the same record.
func (*Store) PruneTasks ¶
func (*Store) Ready ¶
Ready proves connectivity and that the explicitly applied manifest is the exact manifest embedded in this process.
func (*Store) ReadyWithMigrationHistory ¶
func (backend *Store) ReadyWithMigrationHistory(ctx context.Context, manifest schema.Manifest, expectedHistoryDigest string) error
ReadyWithMigrationHistory proves ordinary readiness and exact agreement with the complete ordered migration history embedded in the executable.
func (*Store) RecordFailedLogin ¶
func (*Store) RefreshArtifacts ¶
func (backend *Store) RefreshArtifacts(ctx context.Context, directory string, transforms ...ridumigration.DataTransform) error
RefreshArtifacts rolls back every applied artifact and replays the complete committed schema and callback history in one SQLite transaction.
func (*Store) ReleaseDocumentLock ¶
func (*Store) ReleaseTask ¶
func (*Store) ResetArtifacts ¶
func (backend *Store) ResetArtifacts(ctx context.Context, directory string, transforms ...ridumigration.DataTransform) error
ResetArtifacts rolls back every applied artifact in exact reverse order. Files and their immutable checksums remain untouched, and registered callbacks run in the same transaction.
func (*Store) ResetLoginAttempts ¶
func (*Store) ResetPasswordWithToken ¶
func (*Store) RotateSession ¶
func (*Store) SetPasswordHash ¶
func (*Store) SetPreference ¶
func (backend *Store) SetPreference(ctx context.Context, preference store.Preference) (store.Preference, error)