DRAFTThis page is not published. Only visible in development mode.

Views

A view is derived state the engine maintains for you. You declare a pipeline over source data; ReifyDB builds a dataflow behind it and keeps the result materialized as the sources change. Reading a view is a lookup, never a recomputation. Two decisions define every view: when it is maintained (transactional or deferred) and where its rows live (table, ring buffer, or series).

Transactional views

A transactional view is maintained inside the writing transaction: when a commit returns, the view is already correct. create view and create transactional view are synonyms. Create the view before writing data, then run the snippets on this page in order:

$ A Transactional View Is Maintained by the Write Itself
$ ctrl+enter to run

Write to the source table - there is nothing to refresh and no second system to notify:

$ Write to the Source Table
$ ctrl+enter to run
$ The View Is Already Current
$ ctrl+enter to run

Rows enter and leave with FILTER

When a view's pipeline contains a filter, membership follows the predicate: a source row that matches appears in the view, and a row that stops matching disappears from it.

$ Rows Enter and Leave a Filtered View
$ ctrl+enter to run
$ Only Matching Rows Appear
$ ctrl+enter to run
$ Read the View
$ ctrl+enter to run

Deactivate Alice and she leaves the view - no application code deletes anything from it:

$ A Row That Stops Matching Leaves the View
$ ctrl+enter to run
$ The View Reflects the Change
$ ctrl+enter to run

GATE: membership as an explicit signal

gate also controls membership with a boolean expression, but it models membership as explicit transitions: a row whose gate flips from false to true is recorded as entering the view, changes while true are updates, and a flip back to false is recorded as leaving. Use it when downstream consumers care about the transition itself, not just the current contents:

$ GATE Tracks Membership Explicitly
$ ctrl+enter to run

Bob's active flag is currently false. Flip it and he enters the gated view:

$ A Row Enters When Its Gate Turns True
$ ctrl+enter to run
$ Read the Gated View
$ ctrl+enter to run

Deferred views

A deferred view is maintained asynchronously, driven by the change stream after each commit. Writes stay cheap; the view is eventually consistent and catches up moments later. Declare it with create deferred view:

$ A Deferred View Catches Up After the Commit
$ ctrl+enter to run
$ Write, Then Read the Deferred View
$ ctrl+enter to run

By the time you read it, the deferred flow has processed the change log - here it counts all four orders written on this page, including those written before the view existed:

$ The Deferred View Has Caught Up
$ ctrl+enter to run

Choose transactional views for derived state that reads must never see stale - balances, inventory, anything an invariant depends on. Choose deferred views when a moment of lag is fine and write latency matters - dashboards, counters, feeds.

Backing storage: table, ring buffer, or series

By default a view materializes into table storage. Deferred views can instead materialize into a ring buffer - the derived rows themselves get "keep the last N" semantics:

$ A View Backed by a Ring Buffer
$ ctrl+enter to run
$ The Backing Buffer Evicts Old Derived Rows
$ ctrl+enter to run

Three rows flowed into a capacity-2 buffer; the oldest derived row was evicted:

$ Only the Newest Derived Rows Remain
$ ctrl+enter to run

A series-backed view records its output as a keyed, time-ordered history - derived data you can range-query like any other series:

$ A View Backed by a Series
$ ctrl+enter to run

Views compose

A view can source from another view, and a single write propagates through the whole chain within the same maintenance model:

$ Views Can Source From Other Views
$ ctrl+enter to run
$ One Write Flows Through the Whole Chain
$ ctrl+enter to run
$ Read the End of the Chain
$ ctrl+enter to run

Materialized sort order

A sort inside the view definition materializes the rows in that order, so readers get sorted results without sorting at query time:

$ Materialized Sort Order
$ ctrl+enter to run
Create views before writing data
A view tracks changes from the moment it exists. Transactional views reflect writes that happen after their creation, so declare views alongside your tables, before data starts flowing. Deferred views are driven by the change log and can also process earlier writes, as the order count above shows.