Skip to content

Commit 85c1f3e

Browse files
committed
README update
1 parent e4a1b89 commit 85c1f3e

File tree

1 file changed

+26
-36
lines changed

1 file changed

+26
-36
lines changed

README.md

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,44 @@ _A lightly opinionated DynamoDB library for TypeScript & JavaScript applications
44

55
[DynamoDB](https://aws.amazon.com/dynamodb/) is a cloud-hosted NoSQL database from AWS (Amazon Web Services).
66
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
98
the [basic AWS HTTPS API](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Operations_Amazon_DynamoDB.html).
109

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
1211
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.
1413
Because of this you'll still need to understand how to use DynamoDB from a modeling point of view - I strongly recommend
1514
Alex DeBrie's [book on the subject](https://www.dynamodbbook.com/).
1615

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
21-
[email protected], or use the issues in this project**.
22-
2316
Entity Store provides the following:
2417

25-
* 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 interface for 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.
2922
* 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").
3326
* ... all without any runtime library dependencies, apart from official AWS DynamoDB libraries (AWS SDK V3).
3427

3528
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
3629
collection has the same persisted structure.
3730
Each of these collections is an _Entity_, which also corresponds to a _Domain Type_ within your application's code.
3831

39-
I started a first version of this library in 2022, and have used ideas here in a few projects since.
4032
If you're deciding on what DynamoDB library to choose you may want to also consider the following alternatives:
4133

4234
* [DynamoDB Toolbox](https://github.com/jeremydaly/dynamodb-toolbox) - Jeremy's library was the biggest inspiration to
4335
my own work. When I was looking in 2022 DynamoDB Toolbox didn't support AWS SDK V3, but it does now.
4436
* [One Table](https://github.com/sensedeep/dynamodb-onetable)
4537

4638
The rest of this README provides an overview of how to use the library. For more details see:
47-
* [The manual](./documentation/README.md)
48-
* [integration tests](https://github.com/symphoniacloud/dynamodb-entity-store/tree/main/test/integration)
49-
* [source code](/src/lib)
39+
* [The (comprehensive!) manual](./documentation/README.md)
5040
* [Type Docs](https://symphoniacloud.github.io/dynamodb-entity-store/)
41+
* [Integration tests](https://github.com/symphoniacloud/dynamodb-entity-store/tree/main/test/integration)
42+
* [Source code](/src/lib)
43+
44+
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])
5145

5246
## Example 1: Single Table Design, without indexes
5347

@@ -66,8 +60,6 @@ And let's say we want to store these Sheep in DynamoDB like this:
6660
| `PK` | `SK` | `breed` | `name` | `ageInYears` |
6761
|-----------------------|---------------|-----------|----------|--------------|
6862
| `SHEEP#BREED#merino` | `NAME#shaun` | `merino` | `shaun` | 3 |
69-
| `SHEEP#BREED#merino` | `NAME#bob` | `merino` | `bob` | 4 |
70-
| `SHEEP#BREED#suffolk` | `NAME#alison` | `suffolk` | `alison` | 2 |
7163

7264
We are using a ["Single Table Design"](https://www.alexdebrie.com/posts/dynamodb-single-table/#what-is-single-table-design) configuration here as follows:
7365

@@ -119,7 +111,7 @@ We only need to create this object **once per type** of entity in our applicatio
119111
* **Optional:** express how to convert an object to a DynamoDB record ("formatting")
120112
* **Optional:** Create Global Secondary Index (GSI) key values
121113

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).
123115
124116
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**.
125117

@@ -165,7 +157,8 @@ generator functions as we did for `put` to calculate these, but based on just th
165157
a sheep.
166158

167159
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
169162
attributes include all the properties on a sheep object, but it's possible to customize parsing and/or derive values
170163
from the PK and SK fields if you want to optimize your DynamoDB table - I'll show that a little later.
171164

@@ -192,7 +185,8 @@ when we call `queryAllByPk()`.
192185
Like `getOrThrow`, the result of the query operation is a well-typed list of items - again by using the parser / type
193186
predicate function on `SHEEP_ENTITY` .
194187

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:
196190

197191
```typescript
198192
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
226220
doing. You can do this by turning on logging:
227221

228222
```typescript
229-
const config = createStandardSingleTableConfig('AnimalsTable')
230223
const entityStore = createStore(createStandardSingleTableConfig('AnimalsTable'), { logger: consoleLogger })
231224
```
232225

@@ -309,7 +302,7 @@ export const CHICKEN_ENTITY: Entity<
309302
* `gsis.gsi.sk()` generates the GSI SK
310303
* Remember - a GSI, unlike a table, can include multiple records for the same PK + SK combination
311304

312-
Write operations are no different than before - Entity Store handles generating the GSI PK and SK fields given the
305+
Write operations are no different to code than before, and Entity Store handles generating the GSI PK and SK fields given the
313306
generator functions. So if we have the following...
314307

315308
```typescript
@@ -332,7 +325,7 @@ We can query this entity on the table PK and SK as normal, but let's skip to que
332325
First we can query just on the GSI's PK:
333326

334327
```typescript
335-
console.log('Chickens in Dakota:')
328+
console.log('Chickens in dakota:')
336329
for (const chicken of await chickenStore.queryAllWithGsiByPk({ coop: 'dakota' })) {
337330
console.log(chicken.name)
338331
}
@@ -349,7 +342,7 @@ yolko
349342
And we can also narrow down using the GSI SK values too:
350343

351344
```typescript
352-
console.log('\nOrpingtons in Dakota:')
345+
console.log('Orpingtons in dakota:')
353346
for (const chicken of await chickenStore.queryAllWithGsiByPkAndSk(
354347
{ coop: 'dakota' },
355348
rangeWhereSkBeginsWith('CHICKEN#BREED#orpington')
@@ -372,16 +365,15 @@ involves using very generic PK and SK fields named `PK` and `SK`, using those fi
372365
putting all actual data on non-key attributes.
373366

374367
Entity Store supports other modes of usage though. Let's say we also want to store Farms, in a separate table named
375-
FarmTable, which looks as follows:
368+
`FarmTable`, which looks as follows:
376369

377370
| `Name` | `FarmAddress` |
378371
|------------------|------------------------------------|
379372
| `Sunflower Farm` | `Green Shoots Road, Honesdale, PA` |
380373
| `Worthy Farm` | `Glastonbury, England` |
381374

382375
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.
385377

386378
Our domain code will look like this - **note that the fields on the domain object start with lower case, even though
387379
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
510502

511503
## Next steps
512504

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:
516506

517507
* [Multi-table configuration](documentation/Setup.md)
518508
* [Advanced operations with diagnostic metadata](documentation/AdvancedSingleEntityOperations.md)

0 commit comments

Comments
 (0)