fn(event_type$0, account_id$1, limit$2, offset$3, then$4) =>
#sql<@definy.service-io>({
statements: [
{
sql: "SELECT event_hash, '' AS signed_event_bytes, account_id, event_type, created_at_rfc3339, time_ms FROM events WHERE (? = '' OR REPLACE(LOWER(event_type), '_', '') = REPLACE(LOWER(?), '_', '')) AND (? = '' OR account_id = ?) ORDER BY time_ms DESC, rowid DESC LIMIT ? OFFSET ?",
params: [
#text<@definy.sql-value>($0),
#text<@definy.sql-value>($0),
#text<@definy.sql-value>($1),
#text<@definy.sql-value>($1),
#integer<@definy.sql-value>(@std.min(a: 500, b: @std.max(a: 1, b: $2))),
#integer<@definy.sql-value>(@std.max(a: 0, b: $3))
]
}
],
then: fn(results$5) =>
$4(
events: @core.list-map(
T: @definy.sql-row,
U: @definy.stored-event,
f: fn(item$6) =>
@definy.stored-event-of-row(row: $6),
xs: @definy.sql-rows-concat(results: $5, index: 0)
)
)
})