Giter Club home page Giter Club logo

serverless-kv's Introduction

ServerlessKV

Simple implementation of a key-value store using DynamoDB (more in future?). Overcomes the need for creating complicated models and schemas.

Inspired by @vercel/kv

Usage

Standalone

import kvClient from "@sladg/serverless-kv"

const userKv = kvClient({
  model: "user",
  tableName: process.env.KV_TABLE_NAME!,
})

userKv.insert({ id: "user-id", other: "values", and: "fields" })
userKv.get("user-id")
userKv.delete("user-id")

And you can also use standalone commands:

import { kvCmd } from "@sladg/serverless-kv"

kvCmd.get("table-name", "user-id", "user-model")

SST

This is primarily targeted to be used with SST, in order to do so, we recommend following:

sst.config.ts

import { SSTConfig } from "sst"
import { NextjsSite, Table } from "sst/constructs"

import { sst } from "@sladg/serverless-kv"

const config: SSTConfig = {
  config(_input) {
    return {
      name: "flamingo-dashboard",
      region: "eu-central-1",
    }
  },
  stacks(app) {
    app.stack(function Site({ stack }) {
      const table = new Table(stack, "table01", {
        ...sst.tableConfig,
      })

      const site = new NextjsSite(stack, "site", {
        bind: [table],
        environment: {
          KV_TABLE_NAME: table.tableName,
        },
      })

      stack.addOutputs({
        SiteUrl: site.url,
      })
    })
  },
}

export default config

and then

your-controller.ts

const myKv = kvClient({ model: "user", tableName: process.env.KV_TABLE_NAME })

myKv.get("my-id")

This way, you can use kv outside of pages (aka. in utils folder, or in controllers, etc.)

serverless-kv's People

Contributors

dependabot[bot] avatar sladg avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.