Documentation
¶
Overview ¶
Package sqlite provides a SQLite implementation of the go-sync-kit EventStore.
Index ¶
- Variables
- type Config
- type IntegerVersion
- type SQLiteEventStore
- func (s *SQLiteEventStore) Close() error
- func (s *SQLiteEventStore) LatestVersion(ctx context.Context) (sync.Version, error)
- func (s *SQLiteEventStore) Load(ctx context.Context, since sync.Version) ([]sync.EventWithVersion, error)
- func (s *SQLiteEventStore) LoadByAggregate(ctx context.Context, aggregateID string, since sync.Version) ([]sync.EventWithVersion, error)
- func (s *SQLiteEventStore) ParseVersion(ctx context.Context, versionStr string) (sync.Version, error)
- func (s *SQLiteEventStore) Stats() sql.DBStats
- func (s *SQLiteEventStore) Store(ctx context.Context, event sync.Event, version sync.Version) error
- func (s *SQLiteEventStore) StoreBatch(ctx context.Context, events []sync.EventWithVersion) error
- type StoredEvent
Constants ¶
This section is empty.
Variables ¶
var ( ErrIncompatibleVersion = errors.New("incompatible version type: expected IntegerVersion") ErrEventNotFound = errors.New("event not found") ErrStoreClosed = errors.New("store is closed") )
Custom errors for better error handling
Functions ¶
This section is empty.
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.
EnableWAL bool
// Logger is an optional logger for logging internal operations and errors.
// If nil, logging is disabled.
Logger *log.Logger
// TableName is the name of the table to store events.
// Defaults to "events" if empty.
TableName string
// Connection pool settings
MaxOpenConns int
MaxIdleConns int
ConnMaxLifetime time.Duration
ConnMaxIdleTime time.Duration
}
Config holds configuration options for the SQLiteEventStore.
func DefaultConfig ¶
DefaultConfig returns a Config with sensible defaults for SQLite
type IntegerVersion ¶
type IntegerVersion int64
IntegerVersion implements the sync.Version interface using a simple integer.
func ParseVersion ¶ added in v0.3.0
func ParseVersion(s string) (IntegerVersion, error)
ParseVersion parses a version string into an IntegerVersion. This is useful for HTTP transport and other external integrations.
func (IntegerVersion) Compare ¶
func (v IntegerVersion) Compare(other sync.Version) int
Compare compares this version with another. Returns -1 if this version is less than other, 1 if greater, and 0 if equal.
func (IntegerVersion) IsZero ¶
func (v IntegerVersion) IsZero() bool
IsZero checks if the version is the zero value.
func (IntegerVersion) String ¶
func (v IntegerVersion) String() string
String returns the string representation of the version.
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 sync.Version) ([]sync.EventWithVersion, error)
Load retrieves all events since a given version.
func (*SQLiteEventStore) LoadByAggregate ¶
func (s *SQLiteEventStore) LoadByAggregate(ctx context.Context, aggregateID string, since sync.Version) ([]sync.EventWithVersion, error)
LoadByAggregate retrieves events for a specific aggregate since a given version.
func (*SQLiteEventStore) ParseVersion ¶ added in v0.3.0
func (s *SQLiteEventStore) ParseVersion(ctx context.Context, versionStr string) (sync.Version, error)
ParseVersion converts a string representation into an IntegerVersion. 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 ¶
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 []sync.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 sync.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