SQL Database
Runs a SQL statement against a relational database for each event. It’s built on
sqlx’s Any driver, so the same sink targets SQLite,
PostgreSQL, or MySQL depending on the connection string. Reach for it when you want chain data
landing directly in tables you control.
For every event, the sink renders a Handlebars template into a SQL statement and executes it. There’s one template per kind of chain event:
apply: rendered when a block/tx is applied to the chain.undo: rendered when a block/tx is rolled back.reset: rendered when the pipeline resets to a point (no record is available, only the point).
Configuration
[sink]type = "SqlDb"connection = "sqlite::memory:"apply_template = "INSERT INTO events (slot, data) VALUES ({{point.slot}}, '{{record}}')"undo_template = "DELETE FROM events WHERE slot = {{point.slot}}"reset_template = "DELETE FROM events WHERE slot > {{point.slot}}"type(required): the literal valueSqlDb.connection(required): the sqlx connection string (e.g.sqlite::memory:,sqlite://./oura.db,postgres://user:pass@host/db).apply_template(required): the Handlebars template rendered forapplyevents.undo_template(required): the Handlebars template rendered forundoevents.reset_template(required): the Handlebars template rendered forresetevents.
Template data
Each template is rendered with the following context:
point: the chain point. For a specific point, an object withslot(number) andhash(hex string); for the chain origin,null.record: the event payload.nullforresetevents. For other events its shape depends on the filters before it (raw CBOR hex, a parsed transaction, a legacy v1 event, …) — see the Data Dictionary.