Documentation
¶
Overview ¶
Package store manages the SQLite metadata database for ditto.
Index ¶
- func Open(path string) (*sql.DB, error)
- type Copy
- type CopyStatus
- type CopyStore
- func (s *CopyStore) ClaimWarm(ttlSeconds int) (*Copy, error)
- func (s *CopyStore) CountWarm() (int, error)
- func (s *CopyStore) Create(c *Copy) error
- func (s *CopyStore) Get(id string) (*Copy, error)
- func (s *CopyStore) List(filter ListFilter) ([]*Copy, error)
- func (s *CopyStore) ListExpired() ([]*Copy, error)
- func (s *CopyStore) ListStuck() ([]*Copy, error)
- func (s *CopyStore) UpdateStatus(id string, status CopyStatus, opts ...UpdateOption) error
- type Event
- type EventStore
- type ListFilter
- type UpdateOption
- func WithConnectionString(cs string) UpdateOption
- func WithContainerID(id string) UpdateOption
- func WithDestroyedAt(t time.Time) UpdateOption
- func WithErrorMessage(msg string) UpdateOption
- func WithJobName(s string) UpdateOption
- func WithReadyAt(t time.Time) UpdateOption
- func WithRunID(s string) UpdateOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Copy ¶
type Copy struct {
ID string `json:"id"`
Status CopyStatus `json:"status"`
Port int `json:"port"`
ContainerID string `json:"container_id"`
ConnectionString string `json:"connection_string"`
RunID string `json:"run_id"`
JobName string `json:"job_name"`
ErrorMessage string `json:"error_message"`
CreatedAt time.Time `json:"created_at"`
ReadyAt *time.Time `json:"ready_at"`
DestroyedAt *time.Time `json:"destroyed_at"`
TTLSeconds int `json:"ttl_seconds"`
Warm bool `json:"warm"`
}
Copy is the in-memory representation of a row in the copies table.
type CopyStatus ¶
type CopyStatus string
CopyStatus represents the lifecycle state of an ephemeral database copy.
const ( StatusPending CopyStatus = "pending" StatusCreating CopyStatus = "creating" StatusReady CopyStatus = "ready" StatusInUse CopyStatus = "in_use" StatusDestroying CopyStatus = "destroying" StatusDestroyed CopyStatus = "destroyed" StatusFailed CopyStatus = "failed" )
type CopyStore ¶
type CopyStore struct {
// contains filtered or unexported fields
}
CopyStore wraps a *sql.DB and exposes Copy CRUD operations.
func NewCopyStore ¶
NewCopyStore returns a CopyStore backed by db.
func (*CopyStore) ClaimWarm ¶
ClaimWarm atomically finds one StatusReady warm copy, resets its created_at to NOW (restarting the TTL clock from claim time), marks warm=0, and returns it. Returns sql.ErrNoRows if the pool is empty.
func (*CopyStore) CountWarm ¶
CountWarm returns the number of ready warm copies currently in the pool.
func (*CopyStore) List ¶
func (s *CopyStore) List(filter ListFilter) ([]*Copy, error)
List returns all copies matching filter. Ordered by created_at DESC.
func (*CopyStore) ListExpired ¶
ListExpired returns all READY or IN_USE non-warm copies whose TTL has elapsed.
func (*CopyStore) ListStuck ¶
ListStuck returns copies in CREATING or DESTROYING state (possible mid-crash remnants).
func (*CopyStore) UpdateStatus ¶
func (s *CopyStore) UpdateStatus(id string, status CopyStatus, opts ...UpdateOption) error
UpdateStatus updates the status and optionally other fields for a copy.
type Event ¶
type Event struct {
ID int64
EntityType string
EntityID string
Action string
Actor string
Metadata map[string]any
CreatedAt time.Time
}
Event is a single append-only audit log entry.
type EventStore ¶
type EventStore struct {
// contains filtered or unexported fields
}
EventStore wraps a *sql.DB and exposes the append-only events log.
func NewEventStore ¶
func NewEventStore(db *sql.DB) *EventStore
NewEventStore returns an EventStore backed by db.
type ListFilter ¶
type ListFilter struct {
Statuses []CopyStatus
}
ListFilter controls which copies are returned by List.
type UpdateOption ¶
type UpdateOption func(*updateArgs)
UpdateOption is a functional option for UpdateStatus.
func WithConnectionString ¶
func WithConnectionString(cs string) UpdateOption
func WithContainerID ¶
func WithContainerID(id string) UpdateOption
func WithDestroyedAt ¶
func WithDestroyedAt(t time.Time) UpdateOption
func WithErrorMessage ¶
func WithErrorMessage(msg string) UpdateOption
func WithJobName ¶
func WithJobName(s string) UpdateOption
func WithReadyAt ¶
func WithReadyAt(t time.Time) UpdateOption
func WithRunID ¶
func WithRunID(s string) UpdateOption