GitHub

sql_event_journal

API reference for sql_event_journal.

A journal in a SQL database (Effect's eventlog/SqlEventJournal), on SQLite or PostgreSQL.

Entries live in entry_table; <entry_table>_sequence numbers them in insertion order (uploads checkpoint that number, since ids order creation, not insertion), <entry_table>_sources records the remote each imported entry came from, and the cursors and checkpoints tables keep each remote's download and upload progress. Several processes may share the database: local ids sort after the latest stored id, and on PostgreSQL writers serialize on a table lock so checkpoints cannot skip a commit.

A database written by a release that kept a remotes_table row per entry per remote is migrated in one transaction when opened.

Re-exports

Functions

make

make(*, entry_table='effect_event_journal', remotes_table='effect_event_remotes', remote_cursors_table=None) -> Effect[EventJournalService, SqlError, SqlClient]

A journal in the SqlClient's database, creating or migrating its tables (Effect's SqlEventJournal.make). Fails with ValueError as a defect on a dialect other than SQLite or PostgreSQL.

ParameterTypeDescription
entry_tablestr = 'effect_event_journal'
remotes_tablestr = 'effect_event_remotes'
remote_cursors_tablestr | None = None

Returns Effect[EventJournalService, SqlError, SqlClient]

def make(
    *,
    entry_table: str = "effect_event_journal",
    remotes_table: str = "effect_event_remotes",
    remote_cursors_table: str | None = None,
) -> Effect[EventJournalService, SqlError, SqlClient]:
    """A journal in the ``SqlClient``'s database, creating or migrating its
    tables (Effect's ``SqlEventJournal.make``). Fails with ``ValueError``
    as a defect on a dialect other than SQLite or PostgreSQL."""

    def build():
        sql = (yield from SqlClient()).without_transforms()
        dialect = _dialect(sql)
        tables = _Tables(
            sql,
            entry_table,
            remotes_table,
            remote_cursors_table or f"{remotes_table}_cursors",
        )
        yield from _open_schema(sql, dialect, tables).with_tracer_enabled(False)
        pubsub = yield from PubSub[Entry].unbounded()
        clock = yield from Clock()
        return _SqlJournal(sql, dialect, tables, pubsub, clock)

    return gen(build)

layer

layer(*, entry_table='effect_event_journal', remotes_table='effect_event_remotes', remote_cursors_table=None) -> Layer[EventJournal, SqlError, SqlClient]

The EventJournal of make.

ParameterTypeDescription
entry_tablestr = 'effect_event_journal'
remotes_tablestr = 'effect_event_remotes'
remote_cursors_tablestr | None = None

Returns Layer[EventJournal, SqlError, SqlClient]

def layer(
    *,
    entry_table: str = "effect_event_journal",
    remotes_table: str = "effect_event_remotes",
    remote_cursors_table: str | None = None,
) -> Layer[EventJournal, SqlError, SqlClient]:
    """The ``EventJournal`` of ``make``."""
    return layer_effect(
        EventJournal,
        make(
            entry_table=entry_table,
            remotes_table=remotes_table,
            remote_cursors_table=remote_cursors_table,
        ),
    )