Demux stage-2 rows per channel; produce per-channel histories.
Stage-2 rows are
(checkpoint_id, channel, task_id, idx, type, value, task_path).
Final write order is oldest→newest globally and writes_sort_key
within a checkpoint, matching the contract on
DeltaChannelHistory.writes.
seed is omitted when the walk reached a true root with no snapshot
found (channel never entered seeded); consumers treat absence as
"start empty".
Stage-2 per-channel UNION ALL fetching writes from writes.
One branch per channel with a non-empty chain. Each branch inlines its
own IN (?, ?, ...) placeholder list because sqlite has no array-bind
equivalent of postgres's = ANY(%s). Caller passes parameters in
matching order: [thread_id, checkpoint_ns, channel, *chain_cids] per
branch.
Returns an empty string when no channel has a chain (caller skips
executing in that case). Per-channel UNION ALL avoids the over-fetch
of a single channel = ANY(channels) filter when channels have
different chain depths — same rationale as postgres.
Process one streamed stage-1 row in the merged ancestor walk.
The cursor returns (cid, type, blob) rows in walk order starting at target. The first row is target itself and is skipped (target's own writes/seed are not part of the contract).
For each subsequent row we deserialize the blob, append the cid to
every not-yet-seeded channel's chain, and check channel_values for
seeds. The deserialized checkpoint is dropped before advancing — no
cross-row cache, so peak in-flight is one deserialized checkpoint.
Returns True when the caller can stop iterating and close the cursor: every requested channel is seeded, or the chain revisited a checkpoint.
Deserialize pending_writes_sql rows in writes_sort_key order.
Return WHERE clause predicates for (a)search() given metadata filter
and before config.
This method returns a tuple of a string and a tuple of values. The string is the parametered WHERE clause predicate (including the WHERE keyword): "WHERE column1 = ? AND column2 IS ?". The tuple of values contains the values for each of the corresponding parameters.