Wraith. Store behaviour
(Wraith v0.1.0)
View Source
The one table everything lives in.
Every item is a map with string keys. Two are mandatory — "pk" and
"sk" — and two are optional index keys, "gsi1pk"/"gsi1sk", which
put the item on the single global secondary index. Everything else is the
entity's own business; Wraith.Store.Keys says what goes where.
Adapters (config :wraith, :store):
Wraith.Store.Memory— ETS, for dev and testsWraith.Store.Dynamo— DynamoDB, deployed
Writes are plain puts; put/2 with condition: :not_exists is the
uniqueness primitive (slugs, emails) and condition: {:version, n} the
optimistic-concurrency one (update/3 wraps it). transact/1 applies a
handful of puts and deletes atomically (DynamoDB TransactWriteItems).
Summary
Functions
Every item of a query, pages followed. Use with care.
How many items a query would return (begins_with:/between:/index:
as for query/2), without reading them out: SELECT count(*) on SQL,
Select: COUNT on DynamoDB. For dashboards, not for paging.
The start_key that resumes a query right after item — what query/2
returns as next when item is the last of a page. For callers that
filter a page down and need a cursor at the last item they kept.
A fresh, sortable id: UUIDv7 as a lowercase hex string. Ids minted in the
same millisecond by this node still sort in minting order (a 12-bit
counter in rand_a, UUIDv7 "method 1").
Milliseconds-precision ISO 8601 of now — the sort-key clock.
Items under a partition key (or an index partition when index: :gsi1),
sorted by sort key. begins_with: narrows the sort key, forward: false
walks newest-first, limit: + the returned next page through.
Read-modify-write with optimistic concurrency. fun gets the current
item (or nil) and returns the new one; a concurrent writer makes the
put fail with :conflict and we try again, up to five times.
Types
Callbacks
Functions
Every item of a query, pages followed. Use with care.
@spec count(String.t(), [query_opt()]) :: non_neg_integer()
How many items a query would return (begins_with:/between:/index:
as for query/2), without reading them out: SELECT count(*) on SQL,
Select: COUNT on DynamoDB. For dashboards, not for paging.
The start_key that resumes a query right after item — what query/2
returns as next when item is the last of a page. For callers that
filter a page down and need a cursor at the last item they kept.
A fresh, sortable id: UUIDv7 as a lowercase hex string. Ids minted in the
same millisecond by this node still sort in minting order (a 12-bit
counter in rand_a, UUIDv7 "method 1").
Milliseconds-precision ISO 8601 of now — the sort-key clock.
Items under a partition key (or an index partition when index: :gsi1),
sorted by sort key. begins_with: narrows the sort key, forward: false
walks newest-first, limit: + the returned next page through.
Read-modify-write with optimistic concurrency. fun gets the current
item (or nil) and returns the new one; a concurrent writer makes the
put fail with :conflict and we try again, up to five times.