You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[DynamoDB](https://aws.amazon.com/dynamodb/) is a cloud-hosted NoSQL database from AWS (Amazon Web Services).
6
6
AWS [provides an SDK](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-lib-dynamodb/) for using
7
-
DynamoDB from TypeScript and JavaScript applications but
8
-
it doesn't provide a particularly rich abstraction on top of
7
+
DynamoDB from TypeScript and JavaScript applications but it doesn't provide a particularly rich abstraction on top of
9
8
the [basic AWS HTTPS API](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Operations_Amazon_DynamoDB.html).
10
9
11
-
[_DynamoDB Entity Store_](https://github.com/symphoniacloud/dynamodb-entity-store) is a library which uses the JavaScript V3 SDK from AWS and provides a _slightly_higher level
10
+
[_DynamoDB Entity Store_](https://github.com/symphoniacloud/dynamodb-entity-store) is a library which uses the JavaScript V3 SDK from AWS and provides a higher level
12
11
interface to work with.
13
-
It definitely **is not** an "ORM library", and nor does it try to hide DynamoDB's fundamental behavior.
12
+
It is definitely **not** an "ORM library", and nor does it try to hide DynamoDB's fundamental behavior.
14
13
Because of this you'll still need to understand how to use DynamoDB from a modeling point of view - I strongly recommend
15
14
Alex DeBrie's [book on the subject](https://www.dynamodbbook.com/).
16
15
17
-
**WARNING!! THIS IS AN "ALPHA" VERSION!! I'm releasing an early version of this library to get feedback, but the API may well change in breaking ways over the
18
-
next weeks / months WITHOUT A CORRESPONDING MAJOR RELEASE. I hope to create a stable release by the end of October.**
19
-
20
-
**And since this is an early version I would STRONGLY APPRECIATE FEEDBACK! 😀 Please drop me an email at
*Assistance for write operations, handling repetitive aspects like configuration of table names, key attribute names,
26
-
and setting metadata attributes like "Last Updated" time, and "TTL" (Time To Live)
27
-
* A typed interface, including parsing, for read operations (get, scans, and queries), which also provides entity-scope filtering for collection operations.
28
-
*Capability to automatically load all available results for collection operations (queries and scans), while also providing single-page versions with almost identical interfaces.
18
+
*More simple write operations, handling repetitive aspects like configuration of table names, attributes for keys,
19
+
and setting metadata attributes like "Last Updated" time, and "TTL" (Time To Live).
20
+
* A cleaner interfacefor read operations (get, scans, and queries), including contextual result types, parsing, and automatic "entity type" filtering.
21
+
*Automatically load all available items for query and scan operations (auto-pagination), or choose page-by-page results.
29
22
* Simple setup when using ["Single Table Design"](https://www.alexdebrie.com/posts/dynamodb-single-table/#what-is-single-table-design) ...
30
-
* ... but also allows non-standard and/or multi-table designs
31
-
* A pretty-much-complete coverage of the entire DynamoDB API / SDK, including operations for batch and transaction
32
-
operations, and options for diagnostic metadata (e.g. "consumed capacity")
23
+
* ... but also allows non-standard and/or multi-table designs.
24
+
* A pretty-much-complete coverage of the entire DynamoDB API / SDK, including batch and transaction
25
+
operations, and options for diagnostic metadata (e.g. "consumed capacity").
33
26
* ... all without any runtime library dependencies, apart from official AWS DynamoDB libraries (AWS SDK V3).
34
27
35
28
This library is named _Entity Store_ since it's based on the idea that your DynamoDB tables store one or many collections of related records, and each
36
29
collection has the same persisted structure.
37
30
Each of these collections is an _Entity_, which also corresponds to a _Domain Type_ within your application's code.
38
31
39
-
I started a first version of this library in 2022, and have used ideas here in a few projects since.
40
32
If you're deciding on what DynamoDB library to choose you may want to also consider the following alternatives:
41
33
42
34
*[DynamoDB Toolbox](https://github.com/jeremydaly/dynamodb-toolbox) - Jeremy's library was the biggest inspiration to
43
35
my own work. When I was looking in 2022 DynamoDB Toolbox didn't support AWS SDK V3, but it does now.
If you have questions or feedback, please use the [project issues](https://github.com/symphoniacloud/dynamodb-entity-store/issues), or feel free to email me: [[email protected]](mailto:[email protected])
51
45
52
46
## Example 1: Single Table Design, without indexes
53
47
@@ -66,8 +60,6 @@ And let's say we want to store these Sheep in DynamoDB like this:
We are using a ["Single Table Design"](https://www.alexdebrie.com/posts/dynamodb-single-table/#what-is-single-table-design) configuration here as follows:
73
65
@@ -119,7 +111,7 @@ We only need to create this object **once per type** of entity in our applicatio
119
111
***Optional:** express how to convert an object to a DynamoDB record ("formatting")
120
112
***Optional:** Create Global Secondary Index (GSI) key values
121
113
122
-
> A complete discussion of _Entities_ is available in [the manual, here](./documentation/Entities.md).
114
+
> A complete discussion of _Entities_ is available in [the manual](./documentation/Entities.md).
123
115
124
116
We can now call `.for(...)` on our entity store. This returns an object that implements [`SingleEntityOperations`](https://symphoniacloud.github.io/dynamodb-entity-store/interfaces/SingleEntityOperations.html) - **this is the object that you'll likely work with most when using this library**.
125
117
@@ -165,7 +157,8 @@ generator functions as we did for `put` to calculate these, but based on just th
165
157
a sheep.
166
158
167
159
Note that unlike the AWS SDK's `get` operation here we get a **well-typed result**. This is possible because of the
168
-
[**type-predicate function**](https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates) that we included when creating `SHEEP_ENTITY` . Note that in this basic example we assume that the underlying DynamoDB record
160
+
[**type-predicate function**](https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates) that we included when creating `SHEEP_ENTITY` .
161
+
Note that in this basic example we assume that the underlying DynamoDB record
169
162
attributes include all the properties on a sheep object, but it's possible to customize parsing and/or derive values
170
163
from the PK and SK fields if you want to optimize your DynamoDB table - I'll show that a little later.
171
164
@@ -192,7 +185,8 @@ when we call `queryAllByPk()`.
192
185
Like `getOrThrow`, the result of the query operation is a well-typed list of items - again by using the parser / type
193
186
predicate function on `SHEEP_ENTITY` .
194
187
195
-
A lot of the power of using DynamoDB comes from using the Sort Key as part of a query. Now let's find all sheep of a particular breed, but also where `name` is in a particular alphabetic range:
188
+
A lot of the power of using DynamoDB comes from using the Sort Key as part of a query.
189
+
Now let's find all sheep of a particular breed, but also where `name` is in a particular alphabetic range:
196
190
197
191
```typescript
198
192
function rangeWhereNameBetween(nameRangeStart:string, nameRangeEnd:string) {
@@ -226,7 +220,6 @@ When you're working on setting up your entities and queries you'll often want to
For this table the Partition Key is `Name` and there is no Sort Key. Also note in this case we've chosen **not** to
383
-
store the entity type
384
-
or last-updated values - perhaps this is an old table we're importing into our application.
376
+
store the entity type or last-updated values - perhaps this is an old table we're importing into our application.
385
377
386
378
Our domain code will look like this - **note that the fields on the domain object start with lower case, even though
387
379
those on the table start with upper case** . Again, this is just an example to show what's possible - mixing up
@@ -510,9 +502,7 @@ Name: Sunflower Farm, Address: Green Shoots Road, Honesdale, PA
510
502
511
503
## Next steps
512
504
513
-
If you want to read more on how to use DynamoDB Entity Store, then checkout [the manual](documentation/README.md).
514
-
515
-
[The manual](documentation/README.md) also covers topics not included in this README, including:
505
+
If you want to read more on how to use DynamoDB Entity Store, then checkout [the manual](documentation/README.md), which also covers topics not included in this README:
0 commit comments