dinamo
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

Dinamo

Amazon Dynamo (Amazon DynamoDB) opinionated utilities for Node.js.

NPM version

npm

Getting started

First install the library:

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:

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:

const dinamo = new Dinamo({
  endpoint: 'http://localhost:8000',
  tableName: 'my-table',
})

You can also configure the AWS SDK client logger:

const dinamo = new Dinamo({
  logger: console,
  tableName: 'my-table',
})

Usage

batchGet

Gets items in batch.

await dinamo.batchGet({ keys: [{ id: 'a' }, { id: 'b' }, { id: 'c' }] })

decrement

Decrements an item. Step is optional.

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.

await dinamo.delete({ key: { id: 'a' }, soft: true })

Deletes an item from the database.

await dinamo.delete({ key: { id: 'a' }, soft: false })

get

Gets a single item.

await dinamo.get({ key: { id: 'a' } })

increment

Increments an item. Step is optional.

await dinamo.increment({ key: { id: 'a' }, field: 'count', step: 1 })

put

Puts an item.

await dinamo.put({ item: { id: 'a', foo: 'bar' } })

query

Queries items from the database.

await dinamo.query({ key: { id: 'a' } })

With indexName.

await dinamo.query({ key: { id: 'a' }, indexName: 'dateIdIndex' })

Filtering items.

await dinamo.query({ key: { id: 'a' }, query: { foo: 'bar' } })

Disable filtering soft deletes.

await dinamo.query({ key: { id: 'a' }, filterDeleted: false })

Limiting items.

await dinamo.query({ key: { id: 'a' }, limit: 10 })

Reverse ordering items based on range key.

await dinamo.query({ key: { id: 'a' }, scanIndexForward: true })

scan

Scans items from the database.

await dinamo.scan({ query: { id: 'a' } })

Recursively scan items.

await dinamo.scan({ query: { id: 'a' }, recursive: true })

Disable filtering soft deletes

await dinamo.scan({ query: { id: 'a' }, filterDeleted: false })

update

Updates an item.

await dinamo.update({ key: { id: 'a' }, item: { foo: 'baz' } })

Contributing

Issues and pull requests are welcome.

License

MIT

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
2.0.10latest
1.0.2-990ea6b.00next
0.0.1-alpha.20alpha

Version History

VersionDownloads (Last 7 Days)Published
2.0.10
2.0.00
1.0.2-990ea6b.00
1.0.2-990ea6b.160
1.0.2-990ea6b.150
1.0.2-990ea6b.140
1.0.2-990ea6b.130
1.0.2-990ea6b.120
1.0.2-990ea6b.110
1.0.2-990ea6b.100
1.0.2-990ea6b.90
1.0.2-990ea6b.80
1.0.2-990ea6b.71
1.0.2-990ea6b.60
1.0.2-990ea6b.50
1.0.2-990ea6b.40
1.0.2-990ea6b.30
1.0.2-990ea6b.20
1.0.2-990ea6b.10
1.0.20
1.0.10
1.0.1-12f23e0.00
1.0.00
0.0.1-alpha.170
0.0.1-alpha.160
0.0.1-alpha.150
0.0.1-alpha.140
0.0.1-alpha.130
0.0.1-alpha.120
0.0.1-alpha.110
0.0.1-alpha.100
0.0.1-alpha.90
0.0.1-alpha.80
0.0.1-alpha.70
0.0.1-alpha.60
0.0.1-alpha.50
0.0.1-alpha.40
0.0.1-alpha.30
0.0.1-alpha.20
0.0.1-alpha.10
0.0.1-alpha.00

Package Sidebar

Install

npm i dinamo

Weekly Downloads

0

Version

2.0.1

License

MIT

Unpacked Size

37.7 kB

Total Files

7

Last publish

Collaborators

  • rfoel