GitHub

sql_event_log_server_unencrypted

API reference for sql_event_log_server_unencrypted.

Storage of an unencrypted event log server in a SQL database (Effect's eventlog/SqlEventLogServerUnencrypted), on SQLite, PostgreSQL or MySQL.

Entries of every store share entry_table_prefix, numbered per store from 1 by <entry_table_prefix>_stores. Writes lock their store's row, so writers in other processes queue; changes are published once the outermost transaction commits, and storage-owned transactions hold a permit through commit and publication so changes stream in commit order.

On MySQL store ids, events, primary keys and public keys are in a binary collation, so they compare exactly whatever the database's (_sql_exact_keys).

Re-exports

Functions

make_storage

make_storage(*, entry_table_prefix='effect_events', remote_id_table='effect_remote_id', insert_batch_size=200) -> Effect[StorageService, SqlError, SqlClient | Scope]

Storage in the SqlClient's database, creating its tables (Effect's makeStorage). insert_batch_size rows go in one INSERT (one, if that is below 1, as Effect flushes at the size). Fails with ValueError as a defect on a dialect other than SQLite, PostgreSQL or MySQL.

ParameterTypeDescription
entry_table_prefixstr = 'effect_events'
remote_id_tablestr = 'effect_remote_id'
insert_batch_sizeint = 200

Returns Effect[StorageService, SqlError, SqlClient | Scope]

def make_storage(
    *,
    entry_table_prefix: str = "effect_events",
    remote_id_table: str = "effect_remote_id",
    insert_batch_size: int = 200,
) -> Effect[StorageService, SqlError, SqlClient | Scope]:
    """Storage in the ``SqlClient``'s database, creating its tables
    (Effect's ``makeStorage``). ``insert_batch_size`` rows go in one
    ``INSERT`` (one, if that is below 1, as Effect flushes at the size). Fails
    with ``ValueError`` as a defect on a dialect other than SQLite, PostgreSQL
    or MySQL."""

    def build():
        sql = (yield from SqlClient()).without_transforms()
        dialect = _dialect(sql)
        tables = _Tables(sql, entry_table_prefix, remote_id_table)
        yield from _create_tables(sql, dialect, tables)
        remote_id = yield from _remote_id(sql, tables.remote_id)
        pubsubs = yield from RcMap.make(_open_pubsub, idle_time_to_live="5 minutes")
        semaphore = yield from Semaphore.make(1)
        return _SqlStorage(
            sql=sql,
            dialect=dialect,
            tables=tables,
            remote_id=remote_id,
            pubsubs=pubsubs,
            semaphore=semaphore,
            insert_batch_size=insert_batch_size,
        )

    return gen(build).with_tracer_enabled(False)

layer_storage

layer_storage(*, entry_table_prefix='effect_events', remote_id_table='effect_remote_id', insert_batch_size=200) -> Layer[Storage, SqlError, SqlClient]

The Storage of make_storage.

ParameterTypeDescription
entry_table_prefixstr = 'effect_events'
remote_id_tablestr = 'effect_remote_id'
insert_batch_sizeint = 200

Returns Layer[Storage, SqlError, SqlClient]

def layer_storage(
    *,
    entry_table_prefix: str = "effect_events",
    remote_id_table: str = "effect_remote_id",
    insert_batch_size: int = 200,
) -> Layer[Storage, SqlError, SqlClient]:
    """The ``Storage`` of ``make_storage``."""
    return layer_effect(
        Storage,
        make_storage(
            entry_table_prefix=entry_table_prefix,
            remote_id_table=remote_id_table,
            insert_batch_size=insert_batch_size,
        ),
    )