8000 Duplicate hash keys by tgandrews · Pull Request #33 · tgandrews/omanyd · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Duplicate hash keys #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 22, 2022
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
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
8000
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
Loading
0