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

adonis-dynamodb

v1.2.3

Published

A DynamoDB (Dyngoose) wrapper for AdonisJs.

Downloads

4,976

Readme

Adonis DynamoDB

A DynamoDB (Dyngoose) wrapper for AdonisJs.

gh-workflow-image coverage-image npm-image license-image typescript-image

Dyngoose

What is it?

Dyngoose is a DynamoDB object modeling for Typescript.

Why Dyngoose?

Because it looks like Lucid, you will not be lost. The use of decorators makes it even more attractive.

Docs

You can find all Dyngoose docs here.

Installation

First, install the package using npm or yarn

npm i adonis-dynamodb
# or
yarn add adonis-dynamodb

Next, configure the package by running the following command

node ace configure adonis-dynamodb

Then, add the following namespace to .adonisrc.json file

"namespaces": {
  // ...other namespaces
  "dynamodbTables": "App/Tables" // You can use another namespace.
}

Finally, add the rules for the env variables inside env.ts in your application root:

export default Env.rules({
  // ...other rules
  AWS_REGION: Env.schema.string(),
  AWS_ACCESS_KEY_ID: Env.schema.string(),
  AWS_SECRET_ACCESS_KEY: Env.schema.string(),
})

PS: NEVER share these environment variables.

Usage

Create a new table model

Run the following command to create a table model (it will only create the model file in App/Tables or the namespace of your choice)

node ace dynamo:make Test

By default, the primary key name is id. You can use a custom name by adding a flag to the above command

node ace dynamo:make Test --pk=myPrimaryKey

Create the table(s) on AWS from the model(s)

node ace dynamo:create

This operation may take time. You can also create only one table from a given model by adding the model's name/path.

# Using model's name
node ace dynamo:create Test
# Using model's path (the path is resolved using the namespace defined in .adonisrc.json file as root)
node ace dynamo:create Dir/Test

Delete tables from AWS

You can delete one table from AWS using as follows

# This will delete the table named "Test"
node ace dynamo:drop Test

You can also delete all tables (please be careful when you run this command in production as the drop action is irreversible)

# This will delete all the tables
node ace dynamo:drop

Everytime you run the dynamo:drop command you will be asked if you want to confirm the action.

This command will not delete your models.

Create a new record or update an existing one

Dyngoose will automatically perform an UpdateItem operation if it is possible, to only update the attributes you have changed; but if it is a new record it will perform a PutItem operation.

import Test from 'App/Tables/Test'

const test = await Test.new({
  id: 1
  title: 'Test'
})
await test.save()

// Or
const test = new Test()
test.id = 1
test.title = 'Test'
await test.save()

For more information, please, visit Dyngoose saving docs.

Get an existing record (querying)

// Get record by the primary key
const record = await Test.primaryKey.get({ id: 1 })

if (record) {
  // You need to call toJSON() on the record to get your data serialized.
  console.log(record.toJSON())
}

// Or you can use search() method with filters to get an array of records.
const records = await Test.search({ title: 'Test' }).exec()

records.forEach(record => {
  console.log(record.toJSON())
})

// You can also get all records inside a table using scan() method.
const records = await Test.primaryKey.scan()

records.forEach(record => {
  console.log(record.toJSON())
})

Read more about querying here.

Delete a record

// Get record by the primary key
const record = await Test.primaryKey.get({ id: 1 })

if (record) {
  await record.delete()
}