https://github.com/rfoel/dinamo
Amazon Dynamo (Amazon DynamoDB) opinionated utilities for Node.js.
https://github.com/rfoel/dinamo
aws-sdk dynamo dynamodb hacktoberfest node nodejs
Last synced: about 1 year ago
JSON representation
Amazon Dynamo (Amazon DynamoDB) opinionated utilities for Node.js.
- Host: GitHub
- URL: https://github.com/rfoel/dinamo
- Owner: rfoel
- License: mit
- Created: 2022-09-26T20:28:32.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-01-26T12:46:51.000Z (over 2 years ago)
- Last Synced: 2025-04-16T05:34:25.010Z (about 1 year ago)
- Topics: aws-sdk, dynamo, dynamodb, hacktoberfest, node, nodejs
- Language: TypeScript
- Homepage:
- Size: 837 KB
- Stars: 6
- Watchers: 1
- Forks: 1
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Dinamo
[Amazon Dynamo (Amazon DynamoDB)](https://aws.amazon.com/dynamodb/) _opinionated_ utilities for Node.js.
[](http://badge.fury.io/js/dinamo)
[](https://www.npmjs.com/package/dinamo)
## Getting started
First install the library:
```sh
npm i dinamo @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb
```
> Note that `@aws-sdk/client-dynamodb` and `@aws-sdk/lib-dynamodb` are peer dependencies for this library, so instead of bundling it with the package you MUST install it separately.
Then create an instance in your code:
```js
import Dinamo from 'dinamo'
const dinamo = new Dinamo({ tableName: 'my-table' })
```
If you are using DynamoDB in a Docker container you can pass the endpoint as a parameter:
```js
const dinamo = new Dinamo({
endpoint: 'http://localhost:8000',
tableName: 'my-table',
})
```
You can also configure the AWS SDK client logger:
```js
const dinamo = new Dinamo({
logger: console,
tableName: 'my-table',
})
```
## Usage
### `batchGet`
Gets items in batch.
```js
await dinamo.batchGet({ keys: [{ id: 'a' }, { id: 'b' }, { id: 'c' }] })
```
### `decrement`
Decrements an item. Step is optional.
```js
await dinamo.decrement({ key: { id: 'a' }, field: 'count', step: 1 })
```
### `delete`
Soft deletes an item, i.e., adds a flag `deletedAt` with the timestamp of deletion. This is true by default and `query` and `scan` will filter out the deleted items by default too.
```js
await dinamo.delete({ key: { id: 'a' }, soft: true })
```
Deletes an item from the database.
```js
await dinamo.delete({ key: { id: 'a' }, soft: false })
```
### `get`
Gets a single item.
```js
await dinamo.get({ key: { id: 'a' } })
```
### `increment`
Increments an item. Step is optional.
```js
await dinamo.increment({ key: { id: 'a' }, field: 'count', step: 1 })
```
### `put`
Puts an item.
```js
await dinamo.put({ item: { id: 'a', foo: 'bar' } })
```
### `query`
Queries items from the database.
```js
await dinamo.query({ key: { id: 'a' } })
```
With `indexName`.
```js
await dinamo.query({ key: { id: 'a' }, indexName: 'dateIdIndex' })
```
Filtering items.
```js
await dinamo.query({ key: { id: 'a' }, query: { foo: 'bar' } })
```
Disable filtering soft deletes.
```js
await dinamo.query({ key: { id: 'a' }, filterDeleted: false })
```
Limiting items.
```js
await dinamo.query({ key: { id: 'a' }, limit: 10 })
```
Reverse ordering items based on range key.
```js
await dinamo.query({ key: { id: 'a' }, scanIndexForward: true })
```
### `scan`
Scans items from the database.
```js
await dinamo.scan({ query: { id: 'a' } })
```
Recursively scan items.
```js
await dinamo.scan({ query: { id: 'a' }, recursive: true })
```
Disable filtering soft deletes
```js
await dinamo.scan({ query: { id: 'a' }, filterDeleted: false })
```
### `update`
Updates an item.
```js
await dinamo.update({ key: { id: 'a' }, item: { foo: 'baz' } })
```
## Contributing
Issues and pull requests are welcome.
## License
[MIT](https://github.com/rfoell/dinamo/blob/main/LICENSE)