Documentation
¶
Overview ¶
Package sqlite provides a SQLite implementation of the go-sync-kit EventStore.
Index ¶
- Variables
- func ParseVersion(s string) (cursor.IntegerCursor, error)
- type Config
- type EventEnvelope
- type EventRow
- type SQLiteEventStore
- func (s *SQLiteEventStore) Close() error
- func (s *SQLiteEventStore) LatestVersion(ctx context.Context) (synckit.Version, error)
- func (s *SQLiteEventStore) Load(ctx context.Context, since synckit.Version, filters ...synckit.Filter) ([]synckit.EventWithVersion, error)
- func (s *SQLiteEventStore) LoadByAggregate(ctx context.Context, aggregateID string, since synckit.Version, ...) ([]synckit.EventWithVersion, error)
- func (s *SQLiteEventStore) ParseVersion(ctx context.Context, versionStr string) (synckit.Version, error)
- func (s *SQLiteEventStore) Stats() sql.DBStats
- func (s *SQLiteEventStore) Store(ctx context.Context, event synckit.Event, version synckit.Version) error
- func (s *SQLiteEventStore) StoreBatch(ctx context.Context, events []synckit.EventWithVersion) error
- type StoredEvent
Constants ¶
This section is empty.
Variables ¶
var ( ErrIncompatibleVersion = errors.New("incompatible version type: expected cursor.IntegerCursor") ErrEventNotFound = errors.New("event not found") ErrStoreClosed = errors.New("store is closed") )
Custom errors for better error handling
Functions ¶
func ParseVersion ¶ added in v0.3.0
func ParseVersion(s string) (cursor.IntegerCursor, error)
ParseVersion parses a version string into a cursor.IntegerCursor. This is useful for HTTP transport and other external integrations.
Types ¶
type Config ¶
type Config struct {
// DataSourceName is the connection string for the SQLite database.
// For production use, consider enabling WAL mode for better concurrency.
// Example: "file:events.db?_journal_mode=WAL"
DataSourceName string
// EnableWAL enables Write-Ahead Logging mode for better concurrency.
// This is recommended for production use and is enabled by default.
// When true, automatically appends "?_journal_mode=WAL" to DataSourceName.
EnableWAL bool
// Logger is an optional logger for logging internal operations and errors.
// If nil, logging is disabled by default (logs to io.Discard).
Logger *log.Logger
// TableName is the name of the table to store events.
// Defaults to "events" if empty.
TableName string
// Connection pool settings for production workloads.
// Defaults: MaxOpen=25, MaxIdle=5, Lifetime=1h, IdleTime=5m
MaxOpenConns int // Default: 25 - Maximum number of open connections
MaxIdleConns int // Default: 5 - Maximum number of idle connections
ConnMaxLifetime time.Duration // Default: 1h - Maximum lifetime of connections
ConnMaxIdleTime time.Duration // Default: 5m - Maximum idle time before closing
}
Config holds configuration options for the SQLiteEventStore.
Production-ready defaults are applied by DefaultConfig() including:
- WAL mode enabled for better concurrency
- Connection pool with 25 max open, 5 max idle connections
- Connection lifetimes of 1 hour max, 5 minutes max idle
func DefaultConfig ¶
DefaultConfig returns a Config with production-ready defaults for SQLite.
Default settings include:
- WAL mode enabled for better concurrency
- Connection pool: 25 max open, 5 max idle connections
- Connection lifetime: 1 hour max, 5 minutes max idle
- Table name: "events"
- Logging disabled (to io.Discard)
type EventEnvelope ¶ added in v0.7.0
type EventEnvelope struct {
ID string `json:"id"`
Type string `json:"type"`
AggregateID string `json:"aggregate_id"`
Data map[string]any `json:"data,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
OriginNode string `json:"origin_node,omitempty"`
OriginCounter uint64 `json:"origin_counter,omitempty"`
Seq uint64 `json:"seq,omitempty"`
}
type SQLiteEventStore ¶
type SQLiteEventStore struct {
// contains filtered or unexported fields
}
SQLiteEventStore implements the sync.EventStore interface for SQLite.
func New ¶
func New(config *Config) (*SQLiteEventStore, error)
New creates a new SQLiteEventStore from a Config. If config is nil, DefaultConfig will be used with an empty DataSourceName.
func NewWithDataSource ¶
func NewWithDataSource(dataSourceName string) (*SQLiteEventStore, error)
NewWithDataSource is a convenience constructor
func (*SQLiteEventStore) Close ¶
func (s *SQLiteEventStore) Close() error
Close closes the database connection.
func (*SQLiteEventStore) LatestVersion ¶
LatestVersion returns the highest version number in the store.
func (*SQLiteEventStore) Load ¶
func (s *SQLiteEventStore) Load(ctx context.Context, since synckit.Version, filters ...synckit.Filter) ([]synckit.EventWithVersion, error)
Load retrieves all events since a given version with optional filters.
func (*SQLiteEventStore) LoadByAggregate ¶
func (s *SQLiteEventStore) LoadByAggregate(ctx context.Context, aggregateID string, since synckit.Version, filters ...synckit.Filter) ([]synckit.EventWithVersion, error)
LoadByAggregate retrieves events for a specific aggregate since a given version with optional filters.
func (*SQLiteEventStore) ParseVersion ¶ added in v0.3.0
func (s *SQLiteEventStore) ParseVersion(ctx context.Context, versionStr string) (synckit.Version, error)
ParseVersion converts a string representation into a cursor.IntegerCursor. This allows external integrations to handle SQLite's integer versioning gracefully.
func (*SQLiteEventStore) Stats ¶
func (s *SQLiteEventStore) Stats() sql.DBStats
Stats returns database statistics for monitoring
func (*SQLiteEventStore) Store ¶
func (s *SQLiteEventStore) Store(ctx context.Context, event synckit.Event, version synckit.Version) error
Store saves an event to the SQLite database. Note: This implementation ignores the 'version' parameter and relies on SQLite's AUTOINCREMENT to assign a new, sequential version.
func (*SQLiteEventStore) StoreBatch ¶ added in v0.5.0
func (s *SQLiteEventStore) StoreBatch(ctx context.Context, events []synckit.EventWithVersion) error
StoreBatch stores multiple events in a single transaction for better performance.
type StoredEvent ¶
type StoredEvent struct {
// contains filtered or unexported fields
}
StoredEvent is a concrete implementation of synckit.Event used for retrieving events from the database. It holds data and metadata as raw JSON.
func (*StoredEvent) AggregateID ¶
func (e *StoredEvent) AggregateID() string
func (*StoredEvent) Data ¶
func (e *StoredEvent) Data() interface{}
func (*StoredEvent) ID ¶
func (e *StoredEvent) ID() string
func (*StoredEvent) Metadata ¶
func (e *StoredEvent) Metadata() map[string]interface{}
func (*StoredEvent) Type ¶
func (e *StoredEvent) Type() string