npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@postnord/pretty-dynamo

v0.2.4

Published

An ODM that brings an easy to use interface to DynamoDB

Downloads

7

Readme

Note! This package is deprecated

An abstraction layer on top of the DynamoDB DataMapper. Takes care of the ugly work and exposes a set of readable methods to interact with the database.

Installation

Run npm i @postnord/pretty-dynamo @aws/dynamodb-data-mapper-annotations and you're good to go.

import { PrettyDynamo } from '@postnord/pretty-dynamo'
import { attribute, hashKey, table } from '@aws/dynamodb-data-mapper-annotations'
import * as https from 'https'

@table('users')
class User {
  @hashKey()
  id!: string

  @attribute()
  name!: string
}

const userService = new PrettyDynamo(User, {
  region: 'eu-west-1',
  httpOptions: {
    agent: new https.Agent({
      keepAlive: true,
    }),
  },
})

const createUser = async () => {
  await userService.initDb()
  // The input to those methods will be typed and expecting the schema declared above.
  await userService.createOneRecord({ id: '1', name: 'Jerry' })

  /*
   * The output of the fetching methods will also be typed, so you should expect it to match the declared schema
   * Methods will not throw errors unnecessarily (like when fetching a non existing object) which fixes
   * one of the main design flaws of the native driver.
   */
  const user = await userService.getOneRecord({ id: '1' })
  console.log(user) // variable `user` is undefined if the user does not exist.
}

API

initDb()

Will initialize the DB connection and allow you to use the rest of the functions.

await userService.initDb()

getDb()

Will return the DataMapper object.

const dataMapper = await userService.getDb()

getOneRecord(criteria)

Will grab an object from the database by the specified criteria. Returns undefined if no objects match the given criteria.

const user = await userService.getOneRecord({ id: '1' })

getManyRecords(criteria)

Will query the db for records matching the specified criteria and return an array of matching objects.

const users = await userService.getManyRecords({ name: 'Matt' })

createOneRecord(item)

Will store a new db record.

await userService.createOneRecord({ id: '1', name: 'Estelle' })

createManyRecords(item[])

Will store an array of items to the database.

await userService.createManyRecords([
  { id: '1', name: 'Elaine' },
  { id: '2', name: 'George' },
])

updateOneRecord(criteria, updates)

Will store an array of items to the database. Returns undefined if no items match the criteria.

const updated = await userService.updateOneRecord({ id: '1' }, { name: 'Jackie' })

updateManyRecords(criteria, updates)

Will update all matching objects.

const updated = await userService.updateManyRecords({ name: 'Kramer' }, { name: 'Cosmo' })

deleteOneRecord(criteria)

Will delete the first item matching the criteria. Will return undefined if there were no matches.

const deleted = await userService.deleteOneRecord({ id: '1' })

deleteManyRecords(criteria)

Will delete all matching the criteria. Will return undefined if there were no matches.

await userService.deleteManyRecords({ name: 'Susan' })