https://github.com/socketsupply/dynavolt
A highly opinionated DynamoDB client for aws-sdk v3 using esm.
https://github.com/socketsupply/dynavolt
aws data database dynamo dynamodb key-value kvstore
Last synced: about 2 months ago
JSON representation
A highly opinionated DynamoDB client for aws-sdk v3 using esm.
- Host: GitHub
- URL: https://github.com/socketsupply/dynavolt
- Owner: socketsupply
- Created: 2018-03-28T13:27:31.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-03-28T10:49:42.000Z (about 2 years ago)
- Last Synced: 2025-06-30T06:45:27.158Z (12 months ago)
- Topics: aws, data, database, dynamo, dynamodb, key-value, kvstore
- Language: JavaScript
- Homepage: https://optoolco.github.io/dynavolt/
- Size: 151 KB
- Stars: 2
- Watchers: 4
- Forks: 0
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SYNOPSIS
A highly opinionated DynamoDB client for aws-sdk v3 using esm.
# USAGE
```js
import Dynavolt from 'dynavolt'
const db = new Dynavolt({ region: 'us-west-2' })
```
## TABLES
### CREATE
```js
const { err, data: table } = await db.create('artists')
```
ADVANCED USAGE
You can also specify `hash`, `range`, and `options`.
```js
const opts = { TimeToLiveSpecification: {
AttributeName: 'ttl',
Enabled: true
}
const { err } = await db.create('artists', 'genres', 'artists', opts)
```
### OPEN
Open a database and optionally create it if it doesnt exist.
```js
const { err, data: table } = await db.open('artists', { create: true })
```
## METHODS
### PUT
Dynavolt will automatically (and recursively) deduce the types of your data and
annotate them correctly, so there is no need to write "dynamodb json".
```js
const { err } = await table.put('glen', 'danzig', { height: 'quite-short' })
```
### PUT IF NOT EXISTS
Dynavolt will automatically (and recursively) deduce the types of your data and
annotate them correctly, so there is no need to write "dynamodb json".
```js
const { err } = await table.put('glen', 'danzig', { height: 'quite-short' })
```
### UPDATE
```js
const expr = `SET count = count + N(${value})`
const { err, data } = await table.update('iggy', 'pop', expr)
```
### GET
```js
const { err, data } = await table.get('iggy', 'pop')
```
### DELETE
```js
const { err } = await table.delete('henry', 'rollins')
```
### BATCH WRITE
```js
const { err } = await table.batchWrite([
['foo', 'bar', { beep: 'boop' }],
['foo', 'bar']
])
```
### BATCH READ
```js
const { err } = await table.batchRead([
['foo', 'bazz'],
['beep', 'boop']
])
```
### QUERY
Query takes a [Key Condition Expression][0]. For syntax refernece see the
[Comparison Operator and Function Reference][1].
```js
const iterator = table.query(`hash = N(greetings) AND begins_with(range, S(hell))`)
for await (const { err, data: { key, value } } of iterator) {
console.log(key, value)
}
```
ADVANCED USAGE
You can also chain a [Filter Expression][2] and [Projection Expression][3]
clauses onto querties. More info about Projection Expression syntax [here][4].
```js
const iterator = table
.query(`hash = N(songs) AND begins_with(range, S(moth))`)
.filter(`contains(artists.name, S(danzig)`)
.properties('artists.weight', 'artists.height')
for await (const { err, data: { key, value } } of iterator) {
console.log(key, value)
}
```
### SCAN
Scan takes a [Filter Expression][2].
```js
const iterator = table.scan(`contains(artists.name, S(danzig)`)
for await (const { err, data: { key, value } } of iterator) {
console.log(key, value)
}
```
### TTL
Records in your database can be set to expire by specifying a `TTL` attribute
on your table.
```js
const { err } = await table.setTTL('stillCool')
```
Now one minute after adding the following record, it will be removed.
```js
const opts = {
stillCool: 6e4
}
const { err } = await table.put('brian', 'setzer', { cool: true }, opts)
```
[0]:https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html#Query.KeyConditionExpressions
[1]:https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.OperatorsAndFunctions.html
[2]:https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Scan.html#Scan.FilterExpression
[3]:https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.ProjectionExpressions.html
[4]:https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.Attributes.html