Socket
Book a DemoInstallSign in
Socket

@socketsupply/dynavolt

Package Overview
Dependencies
Maintainers
5
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@socketsupply/dynavolt

A highly opinionated DynamoDB client for aws-sdk v3 using esm.

latest
Source
npmnpm
Version
3.0.0
Version published
Maintainers
5
Created
Source

SYNOPSIS

A highly opinionated DynamoDB client for aws-sdk v3 using esm.

USAGE

import Dynavolt from 'dynavolt'
const db = new Dynavolt({ region: 'us-west-2' })

TABLES

CREATE

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

Open a database and optionally create it if it doesnt exist.

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".

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".

const { err } = await table.put('glen', 'danzig', { height: 'quite-short' })

UPDATE

const expr = `SET count = count + N(${value})`

const { err, data } = await table.update('iggy', 'pop', expr)

GET

const { err, data } = await table.get('iggy', 'pop')

DELETE

const { err } = await table.delete('henry', 'rollins')

BATCH WRITE

const { err } = await table.batchWrite([
  ['foo', 'bar', { beep: 'boop' }],
  ['foo', 'bar']
])

BATCH READ

const { err } = await table.batchRead([
  ['foo', 'bazz'],
  ['beep', 'boop']
])

QUERY

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

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)
}

TTL

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)

FAQs

Package last updated on 28 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts