Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions documentation/dsls/DSL-AshDynamo.DataLayer.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ dynamodb do
table "users"
partition_key :email
sort_key :inserted_at

global_secondary_index :by_status do
partition_key :status
sort_key :inserted_at
end
end
```

Expand All @@ -25,3 +30,24 @@ end
| [`table`](#dynamodb-table){: #dynamodb-table } | `String.t` | | Table name to read from/write to. Defaults to the underscored resource name. |
| [`partition_key`](#dynamodb-partition_key){: #dynamodb-partition_key } | `atom` | | Required partition (hash) key attribute name. |
| [`sort_key`](#dynamodb-sort_key){: #dynamodb-sort_key } | `atom` | `nil` | Optional sort (range) key attribute name. |

### dynamodb.global_secondary_index

Defines a Global Secondary Index (GSI) for automatic query routing.

When a query filters on a GSI's partition key, AshDynamo automatically routes the query to that index instead of scanning the table.

```elixir
global_secondary_index :by_status do
partition_key :status
sort_key :inserted_at
end
```

#### Options

| Name | Type | Default | Docs |
| -------------------------------------------------------------------------------------------------------------------- | ------ | ------- | -------------------------------------------------------- |
| [`name`](#dynamodb-global_secondary_index-name){: #dynamodb-global_secondary_index-name } | `atom` | | Index name (used as the DynamoDB `IndexName` parameter). |
| [`partition_key`](#dynamodb-global_secondary_index-partition_key){: #dynamodb-global_secondary_index-partition_key } | `atom` | | Partition (hash) key attribute for this GSI. |
| [`sort_key`](#dynamodb-global_secondary_index-sort_key){: #dynamodb-global_secondary_index-sort_key } | `atom` | `nil` | Optional sort (range) key attribute for this GSI. |
5 changes: 5 additions & 0 deletions documentation/tutorials/getting-started-with-ash-dynamo.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ defmodule MyApp.Post do
table "posts"
partition_key :id
sort_key :inserted_at

global_secondary_index :by_status do
partition_key :status
sort_key :inserted_at
end
end

actions do
Expand Down
10 changes: 8 additions & 2 deletions lib/ash_dynamo/data_layer/secondary_index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ defmodule AshDynamo.DataLayer.SecondaryIndex do
The `:type` field is auto-set by the entity definition:
- `:global` for Global Secondary Indexes
- `:local` for Local Secondary Indexes

Projection is always `ALL` — every index includes all table attributes.
"""

@type t :: %__MODULE__{
name: atom(),
type: :global | :local,
partition_key: atom(),
sort_key: atom() | nil,
__spark_metadata__: map() | nil
}

defstruct [
:name,
:type,
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
%{
"ash": {:hex, :ash, "3.15.0", "e52c6be244bb22f4afc5eb9fe9cc6e8f034906ef43c114f75c3c372ba6b470c6", [:mix], [{:crux, ">= 0.1.2 and < 1.0.0-0", [hex: :crux, repo: "hexpm", optional: false]}, {:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:ecto, "~> 3.7", [hex: :ecto, repo: "hexpm", optional: false]}, {:ets, "~> 0.8", [hex: :ets, repo: "hexpm", optional: false]}, {:igniter, ">= 0.6.29 and < 1.0.0-0", [hex: :igniter, repo: "hexpm", optional: true]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: false]}, {:picosat_elixir, "~> 0.2", [hex: :picosat_elixir, repo: "hexpm", optional: true]}, {:plug, ">= 0.0.0", [hex: :plug, repo: "hexpm", optional: true]}, {:reactor, "~> 1.0", [hex: :reactor, repo: "hexpm", optional: false]}, {:simple_sat, ">= 0.1.1 and < 1.0.0-0", [hex: :simple_sat, repo: "hexpm", optional: true]}, {:spark, ">= 2.3.14 and < 3.0.0-0", [hex: :spark, repo: "hexpm", optional: false]}, {:splode, "~> 0.3", [hex: :splode, repo: "hexpm", optional: false]}, {:stream_data, "~> 1.0", [hex: :stream_data, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.1", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "adc219ada41d5ec363ef80143404f287d207d0575f93c664a41441d73898306a"},
"ash": {:hex, :ash, "3.16.0", "6389927b322ca7fa7990a75730133db44fcff6368adb63f41cf9eec7a5d38862", [:mix], [{:crux, ">= 0.1.2 and < 1.0.0-0", [hex: :crux, repo: "hexpm", optional: false]}, {:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:ecto, "~> 3.7", [hex: :ecto, repo: "hexpm", optional: false]}, {:ets, "~> 0.8", [hex: :ets, repo: "hexpm", optional: false]}, {:igniter, ">= 0.6.29 and < 1.0.0-0", [hex: :igniter, repo: "hexpm", optional: true]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: false]}, {:picosat_elixir, "~> 0.2", [hex: :picosat_elixir, repo: "hexpm", optional: true]}, {:plug, ">= 0.0.0", [hex: :plug, repo: "hexpm", optional: true]}, {:reactor, "~> 1.0", [hex: :reactor, repo: "hexpm", optional: false]}, {:simple_sat, ">= 0.1.1 and < 1.0.0-0", [hex: :simple_sat, repo: "hexpm", optional: true]}, {:spark, ">= 2.3.14 and < 3.0.0-0", [hex: :spark, repo: "hexpm", optional: false]}, {:splode, "~> 0.3", [hex: :splode, repo: "hexpm", optional: false]}, {:stream_data, "~> 1.0", [hex: :stream_data, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.1", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "1ea69d932ea2ae6cc2971b92576d8ac2721218a8f2f3599e0e25305edb56949b"},
"bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},
"certifi": {:hex, :certifi, "2.15.0", "0e6e882fcdaaa0a5a9f2b3db55b1394dba07e8d6d9bcad08318fb604c6839712", [:rebar3], [], "hexpm", "b147ed22ce71d72eafdad94f055165c1c182f61a2ff49df28bcc71d1d5b94a60"},
"credo": {:hex, :credo, "1.7.16", "a9f1389d13d19c631cb123c77a813dbf16449a2aebf602f590defa08953309d4", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "d0562af33756b21f248f066a9119e3890722031b6d199f22e3cf95550e4f1579"},
Expand Down