sqlite

package
v0.1.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ApplicationID        = 1112493899
	CurrentSchemaVersion = 4
)

Variables

This section is empty.

Functions

func ActiveStatementAccountIdentityDigest

func ActiveStatementAccountIdentityDigest(ctx context.Context, q statementIdentityRowsQueryer, statementAccountID string) (int, string, error)

ActiveStatementAccountIdentityDigest returns a canonical binding for the complete active identity set of one statement account. Every immutable mapping and evidence field is length-prefixed before hashing so field values cannot create ambiguous encodings.

func ComputeBookDigest

func ComputeBookDigest(ctx context.Context, q rowQueryer, bookID, endDate string) (string, error)

func MapError

func MapError(action string, err error) error

MapError converts driver errors into the stable application error contract.

func Migrate

func Migrate(ctx context.Context, path string) error

func NewID

func NewID() (string, error)

func UTCNow

func UTCNow() string

func ValidateMigrationTarget

func ValidateMigrationTarget(ctx context.Context, path string) error

ValidateMigrationTarget verifies, without opening the file for writes, that path is an initialized Books database eligible for forward migrations.

func VerifyAudit

func VerifyAudit(ctx context.Context, db auditQueryer) (int64, error)

Types

type AuditEvent

type AuditEvent struct {
	Sequence      int64           `json:"sequence"`
	EventID       string          `json:"event_id"`
	OccurredAt    string          `json:"occurred_at"`
	Actor         string          `json:"actor"`
	AppVersion    string          `json:"app_version"`
	Command       string          `json:"command"`
	AggregateType string          `json:"aggregate_type"`
	AggregateID   string          `json:"aggregate_id"`
	Payload       json.RawMessage `json:"payload"`
	PreviousHash  string          `json:"previous_hash"`
	EventHash     string          `json:"event_hash"`
}

func AppendAudit

func AppendAudit(ctx context.Context, tx *sql.Tx, input AuditInput) (AuditEvent, error)

type AuditInput

type AuditInput struct {
	Actor         string
	Command       string
	AggregateType string
	AggregateID   string
	Payload       any
}

type BackupResult

type BackupResult struct {
	ID          string `json:"id"`
	Path        string `json:"path"`
	SHA256      string `json:"sha256"`
	CreatedAt   string `json:"created_at"`
	AuditEvents int64  `json:"audit_events"`
}

func Backup

func Backup(ctx context.Context, source *Store, destination, actor string) (result BackupResult, returnErr error)

type DoctorResult

type DoctorResult struct {
	IntegrityCheck             string `json:"integrity_check"`
	ForeignKeyViolations       int    `json:"foreign_key_violations"`
	UnbalancedJournals         int    `json:"unbalanced_journals"`
	InvalidPostedLines         int    `json:"invalid_posted_lines"`
	ClosedDigestFailures       int    `json:"closed_digest_failures"`
	ClosedControlFailures      int    `json:"closed_control_failures"`
	InvalidReconciliations     int    `json:"invalid_reconciliations"`
	InvalidSourceRevisions     int    `json:"invalid_source_revisions"`
	InvalidSourceEvidence      int    `json:"invalid_source_evidence"`
	InvalidMaterializations    int    `json:"invalid_source_materializations"`
	InvalidSourceLinks         int    `json:"invalid_source_links"`
	InvalidStatementLifecycles int    `json:"invalid_statement_lifecycles"`
	AuditEvents                int64  `json:"audit_events"`
	OK                         bool   `json:"ok"`
}

type Mode

type Mode int
const (
	ReadOnly Mode = iota
	ReadWrite
	Create
)

type RestoreBookIdentity

type RestoreBookIdentity struct {
	Code       string `json:"code"`
	Name       string `json:"name"`
	Kind       string `json:"kind"`
	EntityCode string `json:"entity_code,omitempty"`
	GroupCode  string `json:"group_code,omitempty"`
	Basis      string `json:"basis"`
	Currency   string `json:"currency"`
	Status     string `json:"status"`
}

type RestoreEntityIdentity

type RestoreEntityIdentity struct {
	Code      string `json:"code"`
	LegalName string `json:"legal_name"`
	Currency  string `json:"currency"`
	Status    string `json:"status"`
}

type RestoreExpectation

type RestoreExpectation struct {
	DatabaseUUID string
	EntityCode   string
	BookCode     string
}

RestoreExpectation binds a restore to registry identity that remains available even when the target database is missing or has been replaced. Empty fields preserve the advanced direct-database behavior, which binds an existing target to its own database UUID and permits adoption at a new path.

type RestoreResult

type RestoreResult struct {
	Source                     string                  `json:"source"`
	Target                     string                  `json:"target"`
	PreRestoreBackup           string                  `json:"pre_restore_backup,omitempty"`
	SourceSHA256               string                  `json:"source_sha256"`
	SourceDatabaseUUID         string                  `json:"source_database_uuid"`
	PreviousTargetDatabaseUUID string                  `json:"previous_target_database_uuid,omitempty"`
	SourceBaseCurrency         string                  `json:"source_base_currency"`
	SourceEntities             []RestoreEntityIdentity `json:"source_entities"`
	SourceBooks                []RestoreBookIdentity   `json:"source_books"`
}

func Restore

func Restore(ctx context.Context, target, backup, actor string, expected RestoreExpectation) (result RestoreResult, returnErr error)

type RestoreValidation

type RestoreValidation struct {
	Source                     string                  `json:"source"`
	Target                     string                  `json:"target"`
	SourceSHA256               string                  `json:"source_sha256"`
	SourceDatabaseUUID         string                  `json:"source_database_uuid"`
	PreviousTargetDatabaseUUID string                  `json:"previous_target_database_uuid,omitempty"`
	SourceBaseCurrency         string                  `json:"source_base_currency"`
	SourceEntities             []RestoreEntityIdentity `json:"source_entities"`
	SourceBooks                []RestoreBookIdentity   `json:"source_books"`
}

func ValidateRestore

func ValidateRestore(ctx context.Context, target, backup string, expected RestoreExpectation) (RestoreValidation, error)

type Store

type Store struct {
	// contains filtered or unexported fields
}

func Init

func Init(ctx context.Context, path, currency, actor string) (*Store, error)

func Open

func Open(ctx context.Context, path string, mode Mode) (*Store, error)

func (*Store) Begin

func (s *Store) Begin(ctx context.Context) (*sql.Tx, error)

func (*Store) Close

func (s *Store) Close() error

func (*Store) DB

func (s *Store) DB() *sql.DB

func (*Store) Doctor

func (s *Store) Doctor(ctx context.Context) (DoctorResult, error)

func (*Store) Mode

func (s *Store) Mode() Mode

func (*Store) Path

func (s *Store) Path() string

func (*Store) VerifySchema

func (s *Store) VerifySchema(ctx context.Context) error

Jump to

Keyboard shortcuts

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