Typed FSM state: an Ecto embedded schema per FSM, encoded to/from jsonb.
defmodule Checkout.State do
use GenDurable.State
embedded_schema do
field :order, :integer
field :n, :integer, default: 0
end
endThe engine loads the jsonb column into the struct before step/2
(from_db/2) and dumps the returned struct back to jsonb on the outcome
(to_db/2). FSMs may also run with no state module, in which case state is a
plain string-keyed map (allowed, but unsupported — you are on your own).
Summary
Functions
Normalize user-supplied state (for insert) into a JSON string. Accepts the
state struct, or a map (atom or string keys) which is cast through the schema.
Load a DB jsonb value (raw string or already-decoded map) into the FSM state.
Dump an FSM state value returned by a step into a JSON string for a jsonb param.
Functions
Normalize user-supplied state (for insert) into a JSON string. Accepts the
state struct, or a map (atom or string keys) which is cast through the schema.
Load a DB jsonb value (raw string or already-decoded map) into the FSM state.
Dump an FSM state value returned by a step into a JSON string for a jsonb param.