Skip to content

Commit

Permalink
Querying for duplicate hash keys (#33)
Browse files Browse the repository at this point in the history
* No need to wait and endpoint to wait has gone

* Replace start script and use pj for project management

* Add ability to get all items for the hash key

* Add docs

* Bump the minimum version

* Formatting

* Attempt to resolve ipv6 issue

* Run typecheck just once but on the correct node version

* Remove unused branch
  • Loading branch information
tgandrews committed May 22, 2022
1 parent ac1a114 commit e4479a4
Show file tree
Hide file tree
Showing 14 changed files with 10,571 additions and 5,110 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,30 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- name: Read .nvmrc
run: echo "##[set-output name=nvmrc;]$(cat .nvmrc)"
id: nvm
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: ${{ steps.nvm.outputs.nvmrc }}
- run: npm i -g npm@8
- run: npm ci
- run: npm run typecheck
- run: npm run format -- --check
test:
runs-on: ubuntu-latest
strategy:
matrix:
node: ["12", "13", "14"]
node: ["14", "16", "17", "18"]
name: Test on Node ${{ matrix.node }}
steps:
- uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- run: npm i -g npm@8
- run: npm ci
- run: npm run test -- --coverage
- name: coverage
Expand Down
3 changes: 3 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env sh
. "$(dirname "$0")/_/husky.sh"
npx lint-staged
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16
3 changes: 3 additions & 0 deletions .pjconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[[window]]
name = "omanyd"
command = "npm run test -- --watch"
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,50 @@ console.log(readTweet);
*/
```

### Reading many - items with hash and range key

When an item has a hash and range key then this means you can have multiple items for the one hash key as their range keys are different.
To retrieve all of the items for a hash key:

```ts
interface EditableTweet {
id: string;
version: number;
content: string;
}
const EditableTweetStore = Omanyd.define<EditableTweet>({
name: "Tweet",
hashKey: "id",
rangeKey: "version",
schema: Joi.object({
id: Omanyd.types.id(),
version: Joi.number(),
content: Joi.string(),
}),
});

await Promise.all([
EditableTweetStore.create({
id: "958f2b51-774a-436a-951e-9834de3fe559",
version: 1,
content: "My tweet",
}),
EditableTweetStore.create({
id: "958f2b51-774a-436a-951e-9834de3fe559",
version: 2,
content: "My tweet edited",
}),
]);

const tweets = await EditableTweetStore.getAllByHashKey("id");
console.log(tweets);
/* [
* { id: "958f2b51-774a-436a-951e-9834de3fe559", version: 1, content: "My tweet" },
* { id: "aa6ea347-e3d3-4c73-8960-709fa47e3a4c", version: 2, content: "My tweet edited" },
* ]
*/
```

### Reading many - scanning

If we want all of the items in the store we can use a scan. DynamoDB scans come with some [interesting caveats](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Scan.html).
Expand Down

0 comments on commit e4479a4

Please sign in to comment.