SQLite implementations for eventium.
Eventium-sqlite provides a SQLite-based event store implementation for the Eventium event sourcing framework. It uses the Persistent library for type-safe database access and provides efficient event storage and retrieval with support for aggregate streams, event versioning, and optimistic concurrency control. This backend is ideal for single-process applications, embedded systems, and scenarios where a lightweight database is preferred.
Eventium SQLite
SQLite event store backend for Eventium.
Overview
eventium-sqlite provides a lightweight, file-based event store using SQLite. Ideal for CLI tools, single-process applications, and development environments where a full database server is unnecessary.
API
sqliteEventStoreWriter
:: (MonadIO m)
=> SqlEventStoreConfig entity serialized
-> VersionedEventStoreWriter (SqlPersistT m) serialized
initializeSqliteEventStore
:: (MonadIO m)
=> SqlEventStoreConfig entity serialized
-> ConnectionPool
-> m ()
Readers come from eventium-sql-common (re-exported):
sqlEventStoreReader :: SqlEventStoreConfig entity serialized -> VersionedEventStoreReader (SqlPersistT m) serialized
sqlGlobalEventStoreReader :: SqlEventStoreConfig entity serialized -> GlobalEventStoreReader (SqlPersistT m) serialized
Usage
import Eventium.Store.Sqlite
import Database.Persist.Sqlite
main :: IO ()
main = runNoLoggingT $ do
pool <- createSqlitePool "events.db" 1
liftIO $ initializeSqliteEventStore defaultSqlEventStoreConfig pool
let writer = sqliteEventStoreWriter defaultSqlEventStoreConfig
reader = sqlEventStoreReader defaultSqlEventStoreConfig
-- writer and reader operate in SqlPersistT m
initializeSqliteEventStore runs migrations and creates a UUID index.
When to Use
| Scenario | Recommendation |
|---|---|
| CLI tools, desktop apps | SQLite |
| Development / prototyping | SQLite or Memory |
| Multi-process / production | PostgreSQL |
| Unit tests (no persistence needed) | Memory |
Installation
dependencies:
- eventium-core
- eventium-sqlite
- persistent-sqlite
Documentation
- Main README
- SQL Common
- Design
- Cafe Example and Bank Example both use SQLite
License
MIT -- see LICENSE.md.