View Source Dynamo.Request (Dynamo v0.2.0)

Pure builders for DynamoDB request payloads.

Every function returns {:ok, {action, payload}} or {:error, %Dynamo.Error{}} and performs no I/O. Dynamo.Repo executes them through Dynamo.Client. Because they are pure they can be unit-tested against the exact JSON DynamoDB expects.

Common options

Most builders accept these expression options:

  • :condition – ConditionExpression string
  • :filter – FilterExpression string (query/scan)
  • :projection – ProjectionExpression string or list of field atoms
  • :names – map of "#placeholder" => "attribute" (ExpressionAttributeNames)
  • :values – map of ":placeholder" => value. Values that are not already DynamoDB attribute values (Dynamo.Raw) are dumped with :any.
  • :return_values – :none | :all_old | :all_new | :updated_old | :updated_new

  • :return_consumed_capacity – :none | :total | :indexes

Summary

Functions

BatchGetItem for up to 100 structs (same schema).

BatchWriteItem for up to 25 structs (mixed schemas/tables allowed). {:delete, struct} tuples delete instead of put.

GetItem for a schema struct with populated key fields.

PutItem for a schema struct.

Query. The partition key is taken from the struct (table or :index). The sort key condition comes from :sort_key

Scan a schema's table (or :index). Supports :segment/:total_segments.

SearchVectors on a schema's vector index.

TransactWriteItems. Each operation is one of

UpdateItem. changes is a keyword/map of field => change (see Dynamo.Update), or pass update_expression: with names:/values: for a raw expression.

Types

action()

@type action() :: String.t()

payload()

@type payload() :: map()

result()

@type result() :: {:ok, {action(), payload()}} | {:error, Dynamo.Error.t()}

Functions

batch_get(structs, opts \\ [])

@spec batch_get(
  [struct()],
  keyword()
) :: result()

BatchGetItem for up to 100 structs (same schema).

batch_write(items, opts \\ [])

@spec batch_write(
  [struct() | {:delete, struct()}],
  keyword()
) :: result()

BatchWriteItem for up to 25 structs (mixed schemas/tables allowed). {:delete, struct} tuples delete instead of put.

delete(struct, opts \\ [])

@spec delete(struct(), keyword()) :: result()

DeleteItem.

get(struct, opts \\ [])

@spec get(struct(), keyword()) :: result()

GetItem for a schema struct with populated key fields.

put(struct, opts \\ [])

@spec put(struct(), keyword()) :: result()

PutItem for a schema struct.

query(struct, opts \\ [])

@spec query(struct(), keyword()) :: result()

Query. The partition key is taken from the struct (table or :index). The sort key condition comes from :sort_key:

  • omitted – if the struct has sort-key fields populated: begins_with on the generated (possibly partial) composite sort key for table queries, or equality for index / raw_keys queries (single typed attribute); otherwise partition only
  • {:eq, v}, {:lt, v}, {:lte, v}, {:gt, v}, {:gte, v}, {:begins_with, v}, {:between, lo, hi} – explicit condition; v is the raw sort key value (string for composite keys, typed value for GSI/raw keys)
  • :none – partition key only, ignore struct sort-key fields

Other options: :filter, :projection, :names, :values, :limit, :start_key, :consistent (not allowed with :index), :descending, :select (:count, :all_attributes, :all_projected_attributes).

scan(mod, opts \\ [])

@spec scan(
  module(),
  keyword()
) :: result()

Scan a schema's table (or :index). Supports :segment/:total_segments.

search_vectors(mod, index_name, vector, opts \\ [])

@spec search_vectors(module(), String.t(), [number()], keyword()) :: result()

SearchVectors on a schema's vector index.

  • vector – list of floats; its length must match the index dimensions
  • :top_k – 1..100 (default 10)
  • :filter – SearchConditionExpression; string or Dynamo.Condition DSL. When the index has a partition_key, the filter MUST include [partition_field: value] (DynamoDB requires it).
  • :projection – attributes to return (only projected ones are available); the vector itself is not returned unless you ask for it here
  • :return_consumed_capacity – :total | :indexes | :none

transact_write(operations, opts \\ [])

@spec transact_write(
  [tuple()],
  keyword()
) :: result()

TransactWriteItems. Each operation is one of:

  • {:put, struct, opts} – opts: :condition, :names, :values
  • {:update, struct, changes, opts}
  • {:delete, struct, opts}
  • {:check, struct, condition, opts} – ConditionCheck

(opts may be omitted.) Top-level opts: :client_request_token for idempotency, :return_consumed_capacity.

update(struct, changes, opts \\ [])

@spec update(struct(), keyword() | map(), keyword()) :: result()

UpdateItem. changes is a keyword/map of field => change (see Dynamo.Update), or pass update_expression: with names:/values: for a raw expression.