A highly opinionated DynamoDB client for aws-sdk v3 using esm.
import Dynavolt from 'dynavolt'
const db = new Dynavolt({ region: 'us-west-2' })
const { err, data: table } = await db.create('artists')
ADVANCED USAGE
You can also specify hash
, range
, and options
.
const opts = { TimeToLiveSpecification: {
AttributeName: 'ttl',
Enabled: true
}
const { err } = await db.create('artists', 'genres', 'artists', opts)
Open a database and optionally create it if it doesnt exist.
const { err, data: table } = await db.open('artists', { create: true })
Dynavolt will automatically (and recursively) deduce the types of your data and annotate them correctly, so there is no need to write "dynamodb json".
const { err } = await table.put('glen', 'danzig', { height: 'quite-short' })
Dynavolt will automatically (and recursively) deduce the types of your data and annotate them correctly, so there is no need to write "dynamodb json".
const { err } = await table.put('glen', 'danzig', { height: 'quite-short' })
const expr = `SET count = count + N(${value})`
const { err, data } = await table.update('iggy', 'pop', expr)
const { err, data } = await table.get('iggy', 'pop')
const { err } = await table.delete('henry', 'rollins')
const { err } = await table.batchWrite([
['foo', 'bar', { beep: 'boop' }],
['foo', 'bar']
])
const { err } = await table.batchRead([
['foo', 'bazz'],
['beep', 'boop']
])
Query takes a Key Condition Expression. For syntax refernece see the Comparison Operator and Function Reference.
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 and Projection Expression clauses onto querties. More info about Projection Expression syntax here.
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 takes a Filter Expression.
const iterator = table.scan(`contains(artists.name, S(danzig)`)
for await (const { err, data: { key, value } } of iterator) {
console.log(key, value)
}
Records in your database can be set to expire by specifying a TTL
attribute
on your table.
const { err } = await table.setTTL('stillCool')
Now one minute after adding the following record, it will be removed.
const opts = {
stillCool: 6e4
}
const { err } = await table.put('brian', 'setzer', { cool: true }, opts)