ex_state v0.2.0 ExState.Ecto.Query View Source

ExState.Ecto.Query provides functions for querying workflow state in the database through Ecto.

Link to this section Summary

Functions

where_any_state/2 takes a subject query and a state and filters based on workflows that are equal to or in a child state of the given state. Nested states can be passed as a list of states and will be converted to a valid state identifier in the query.

where_state/2 takes a subject query and state and filters based on workflows that are in the exact state that is passed. Nested states can be passed as a list of states and will be converted to a valid state identifier in the query.

where_state_in/2 takes a subject query and a list of states and filters based on workflows that are in one of the exact states that are passed. Nested states can be passed as a list of states and will be converted to a valid state identifier in the query.

Link to this section Functions

Link to this function

where_any_state(subject_query, state)

View Source

where_any_state/2 takes a subject query and a state and filters based on workflows that are equal to or in a child state of the given state. Nested states can be passed as a list of states and will be converted to a valid state identifier in the query.

Examples:

investment #=> %Investment{workflow: %Workflow{state: "subscribing.confirming_options"}}

Investment
|> where_any_state(:subscribing)
|> Repo.all()                                                 #=> [investment]

Investment
|> where_any_state("subscribing")
|> Repo.all()                                                 #=> [investment]

Investment
|> where_any_state([:subscribing, :confirming_options])
|> Repo.all()                                                 #=> [investment]

Investment
|> where_any_state(:resubmitting)
|> Repo.all()                                                 #=> []
Link to this function

where_state(subject_query, state)

View Source

where_state/2 takes a subject query and state and filters based on workflows that are in the exact state that is passed. Nested states can be passed as a list of states and will be converted to a valid state identifier in the query.

Pass the state as the keyword list not: state in order to query the inverse.

Examples:

investment #=> %Investment{workflow: %Workflow{state: "subscribing.confirming_options"}}

Investment
|> where_state("subscribing.confirming_options")
|> Repo.all()                                                 #=> [investment]

Investment
|> where_state([:subscribing, :confirming_options])
|> Repo.all()                                                 #=> [investment]

Investment
|> where_state(["subscribing", "confirming_options"])
|> Repo.all()                                                 #=> [investment]

Investment
|> where_state(:subscribing)
|> Repo.all()                                                 #=> []

Investment
|> where_state(not: [:subscribing, :confirming_suitability])
|> Repo.all()                                                 #=> [investment]

Investment
|> where_state(not: [:subscribing, :confirming_options])
|> Repo.all()                                                 #=> []
Link to this function

where_state_in(subject_query, states)

View Source

where_state_in/2 takes a subject query and a list of states and filters based on workflows that are in one of the exact states that are passed. Nested states can be passed as a list of states and will be converted to a valid state identifier in the query.

Pass the state as the keyword list not: state in order to query the inverse.

Examples:

investment1 #=> %Investment{workflow: %Workflow{state: "subscribing.confirming_options"}}
investment2 #=> %Investment{workflow: %Workflow{state: "executed"}}

Investment
|> where_state_in([
  [:subscribing, :confirming_options],
  :executed
])
|> Repo.all()                                                 #=> [investment1, investment2]

Investment
|> where_state_in(["subscribing.confirming_options"])
|> Repo.all()                                                 #=> [investment1]

Investment
|> where_state_in([:subscribing])
|> Repo.all()                                                 #=> []

Investment
|> where_state_in(not: [[:subscribing, :confirming_options]])
|> Repo.all()                                                 #=> [investment2]

Investment
|> where_state_in(not: [:subscribing])
|> Repo.all()                                                 #=> [investment1, investment2]
Link to this function

where_step_complete(q, s)

View Source