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

@cyclic.sh/dynamodb

v0.0.35

Published

SDK for interacting with Cyclic.sh (https://cyclic.sh) app AWS DynamoDB databases

Downloads

117

Readme

@cyclic.sh/dynamodb

NodeJS SDK for interacting with Cyclic.sh app AWS DynamoDB databases.

Discord CI semantic-release: angular

npm (scoped) node-current (scoped) npm bundle size (scoped) @cyclic.sh/dynamodb

Together with the Cyclic.sh DynamoDB indexing strategy and data model, the SDK simplifies the DynamoDB interface and enables collection organization of records, queries, and data scheme discovery, among other features.

We use semantic release for versioning so take note of version numbers.

Prerequisites

  • A Cyclic.sh app with database enabled
  • For use on local:
    • AWS credentials set in environment (available on an app's database tab)

Getting started

  1. Install
    npm install @cyclic.sh/dynamodb
  2. Copy the temporary credentials from the Cyclic.sh console and set them in the shell environment where your code is running.

Credentials are required only for connecting to the database from local and expire after one hour, don't add them to an environment configuration.

  1. Set the database name as an environment variable before requiring the SDK - this can be added to environment configurations.
    process.env.CYCLIC_DB = 'your-url-subdomainCyclicDB'
    const db = require('@cyclic.sh/dynamodb')

Example

// example.js
const CyclicDB = require('@cyclic.sh/dynamodb')
const db = CyclicDB('your-table-name')

const run = async function(){
    let animals = db.collection('animals')

    // create an item in collection with key "leo"
    let leo = await animals.set('leo', {
        type:'cat',
        color:'orange'
    })

    // get an item at key "leo" from collection animals
    let item = await animals.get('leo')
    console.log(item)
}
run()

Collection Items

{
  "collection": "animals",
  "key": "luna",
  "props": {
    "updated": "2022-03-23T13:02:12.702Z",
    "created": "2022-03-23T12:32:02.526Z",
    "color": "orange",
    "type": "cat"
  },
  "$index": [
    "color"
  ]
}

Fragments

With the Cyclic.sh data model, items can have fragments. These can be thought of as children or attachments to items.

Another way to think of fragments is by thinking of an item itself as its own collection of other items that are stored closely together.

An example use case for a user record would be something like:

  • item user: name, last name, id
    • fragment home: address, city
    • fragment work: company name, position, work address

Fragments objects look just like items but give you a way to better organize your data with higher query performance.

Example:

let users = db.collection('users')

await users.item('mike')
        .fragment('work').set({
            company: 'cyclic'
        })

let mikes_work = await users.item('mike').fragment('work').get()

TTL - Time To Live

You optionally may set a TTL for any item. The TTL is the UNIX seconds timestamp when the item should expire.

The TTL setting passes through to the DynamoDB TTL setting. The expiration is only approximate within a few minutes.

Example

// example.js
const CyclicDB = require('@cyclic.sh/dynamodb')
const db = CyclicDB('your-table-name')

const run = async function(){
    let animals = db.collection('animals')

    // create an item in collection with key "leo"
    let leo = await animals.set('leo', {
        type:'cat',
        color:'orange',
        ttl: Math.floor(Date.now() / 1000) + 3
    })

    // get an item at key "leo" from collection animals
    let item = await animals.get('leo')
    console.log(item)

    await new Promise(resolve => setTimeout(resolve, 5000));
    
    item = await animals.get('leo')
    console.log(item)
}
run()