View Source Dynamo.Condition (Dynamo v0.2.0)

Builds ConditionExpression / FilterExpression strings from Elixir terms, generating attribute-name and value placeholders so you never write names:/values: by hand.

Any condition: or filter: option accepts either a raw string (with your own names:/values:) or one of these forms:

# keyword list = AND of field conditions
condition: [status: "open", version: {:eq, 3}]
condition: [age: {:gt, 18}, tags: {:contains, "vip"}, name: {:begins_with, "A"}]
condition: [price: {:between, 10, 20}, kind: {:in, ["a", "b"]}]
condition: [email: :exists, legacy: :not_exists]
condition: [total: {:size, {:gt, 3}}, meta: {:attribute_type, "M"}]

# combinators
condition: {:or, [status: "open"], [status: "pending"]}
condition: {:and, [a: 1], {:not, [b: 2]}}

Field operators: a plain value means =; {:eq | :ne | :lt | :lte | :gt | :gte, v}, {:between, lo, hi}, {:in, [v, ...]}, {:begins_with, s}, {:contains, v}, :exists / :not_exists, {:attribute_type, "S" | "N" | ...}, {:size, {op, n}}.

Fields may be atoms, strings, or nested paths as lists ([:address, :city] → #a0.#a1). Values are dumped with the schema's field type for top-level fields when a schema is given, otherwise inferred (:any).

Placeholders are #c0… and :c0… so they never collide with the #a0/:v0 placeholders from Dynamo.Update or :pk/:sk from key conditions.

Summary

Functions

Compiles a condition. Strings pass through untouched (names/values empty). Returns {:ok, expression, names, values}.

Types

t()

@type t() :: keyword() | {:and | :or, t(), t()} | {:not, t()} | String.t()

Functions

build(schema, cond, prefix \\ "c")

@spec build(module() | nil, t(), String.t()) ::
  {:ok, String.t(), map(), map()} | {:error, Dynamo.Error.t()}

Compiles a condition. Strings pass through untouched (names/values empty). Returns {:ok, expression, names, values}.