Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dynamodb-toolbox/dynamodb-toolbox
Lightweight and type-safe query builder for DynamoDB and TypeScript
https://github.com/dynamodb-toolbox/dynamodb-toolbox
aws dynamodb nosql serverless typescript
Last synced: 3 days ago
JSON representation
Lightweight and type-safe query builder for DynamoDB and TypeScript
- Host: GitHub
- URL: https://github.com/dynamodb-toolbox/dynamodb-toolbox
- Owner: dynamodb-toolbox
- License: mit
- Created: 2019-11-24T23:16:45.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2025-02-04T10:48:55.000Z (10 days ago)
- Last Synced: 2025-02-04T11:15:38.669Z (10 days ago)
- Topics: aws, dynamodb, nosql, serverless, typescript
- Language: TypeScript
- Homepage: https://www.dynamodbtoolbox.com/
- Size: 19.7 MB
- Stars: 1,876
- Watchers: 26
- Forks: 179
- Open Issues: 48
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - dynamodb-toolbox/dynamodb-toolbox - Lightweight and type-safe query builder for DynamoDB and TypeScript (TypeScript)
README
![dynamodb-toolbox](https://user-images.githubusercontent.com/2053544/69847647-b7910780-1245-11ea-8403-a35a0158f3aa.png)
π _Huge thanks to the [sponsors](https://github.com/sponsors/ThomasAribart) who help me maintain this repo:_
# DynamoDB-Toolbox
---
Light-weight and type-safe
query builder for DynamoDB and TypeScript.---
DynamoDB-Toolbox is a light abstraction layer over the DocumentClient that **turns your DynamoDB journey into a β¨ bliss β¨**
## Features
π€ **Simpler queries**: DynamoDB-Toolbox does all the heavy-lifting of crafting those **complex DynamoDB requests**. It makes your code **clearer**, **more concise** and **easier to maintain**.
π **Data validation**: Both pushed and fetched items are **validated** against your schemas, which guarantees the **consistency** of your data and the **reliability** of your code.
β¨ **A rich schema syntax** that supports a broad range of edge cases like **defaults**, **composition**, **transformation** and **polymorphism**.
π **Type-safety pushed to the limit**: Increase your development velocity with **instantaneous feedbacks** and **slick auto-completion**.
π΄ **Tree-shakable**: Only import what you need.
βοΈ **Single-table designs**: DynamoDB-Toolbox makes **querying multiple entities within the same table extremely simple**, although it works just as well with multiple tables.
πͺΆ **LLRT compatible**: DynamoDB-Toolbox has no dependency and can be used within [LLRT functions](https://github.com/awslabs/llrt).
## Visit the π [official documentation](https://dynamodbtoolbox.com/) π to get started!
## Why use it?
If you're here, we're assuming you know DynamoDB.
If you don't, check out the [official AWS docs](https://aws.amazon.com/dynamodb).
> **TLDR**: _[DynamoDB](https://aws.amazon.com/dynamodb) is a key-value DB designed to run high-performance applications at any scale. It **automatically scales** up and down based on your current traffic, and removes the need to maintain connections, which makes it the **go-to DB for many projects**, including (but not limited to) **serverless applications**._
If you've ever used the official [Document Client](https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/dynamodb-example-dynamodb-utilities.html), you know that **itβs painful to use**.
Take a look at this `UpdateCommand` example straight from the [AWS documentation](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/dynamodb/command/UpdateItemCommand/):
```ts
await documentClient.send(
new UpdateCommand({
TableName: 'Music',
Key: {
// π No type-safety on the Primary Key
artist: 'Acme Band',
songTitle: 'Happy Day'
},
// π Complex string expressions (+ still no type-safety)
UpdateExpression: 'SET #Y = :y, #AT = :t',
// π Attribute names provided separately
ExpressionAttributeNames: {
'#AT': 'albumTitle',
'#Y': 'year'
},
// π Attribute values as well
ExpressionAttributeValues: {
// π No validation or type-safety to enforce DB schema
':t': 'Louder Than Ever',
':y': '2015'
},
ReturnValues: 'ALL_NEW'
})
)
```It's a very simple example (updating two fields of a `Music` item), yet already complex π°
**Things only get messier as your data grows in complexity**: What if your items have many attributes, with some of them deep or optional? What if you need to index an item based on its value or handle different types of items? What about polymorphism?
In those cases, which are fairly common, **the required code to generate those requests gets very hard to maintain**. That's when DynamoDB-Toolbox comes to the rescue πͺ
Here's is a quick preview with the DynamoDB-Toolbox version of the `UpdateCommand` described above:
```ts
// Validated AND type-safe syntax π
await MusicEntity.build(UpdateItemCommand)
.item({
artist: 'Acme Band',
songTitle: 'Happy Day',
albumTitle: 'Louder Than Ever',
year: '2015'
})
.options({ returnValues: 'ALL_NEW' })
.send()
```And just like that, we went from an obscure 20 lines to a **readable and elegant 10-liner** π€©
Not bad, eh? [Let's get started](https://dynamodbtoolbox.com/)!
### [Become a Sponsor!](https://github.com/sponsors/thomasaribart/)