GithubHelp home page GithubHelp logo

zakyg / tinymo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from parana-games/tinymo

0.0 0.0 0.0 136 KB

Simple AWS DynamoDB wrapper for Node/TypeScript

License: MIT License

JavaScript 0.30% TypeScript 99.70%

tinymo's Introduction

test

Constructing DynamoDB's JSON-based command inputs can get challenging.

tinymo is here to help!

๐Ÿ˜จ

const update = {
  TableName: 'users',
  Key: { 
    id: 'john' 
  },
  UpdateExpression: 'ADD #orders :orders',
  ConditionExpression: '#balance > :balanceCondition',
  ExpressionAttributeNames: { 
    '#balance': 'balance', 
    '#orders': 'orders' 
  },
  ExpressionAttributeValues: { 
    ':balanceCondition': 10, 
    ':orders': 1 
  }
}

๐Ÿ˜Œ

const update = tinymo.update('users', { id: 'john' });
update.add('orders', 1);
update.condition('balance', '>', 10);

Features

Chaining!

update.set('name', 'John').add('age', 30).remove('address');

Transactions!

const transaction = tinymo.transaction();

transaction.delete('users', { pk: 'jeff', id: 'order#001' });
transaction.update('stores', { id: 'amazon' }).add('balance', 1);

Batch writes!

const batchWrite = tinymo.batchWrite();

batchWrite.delete('stores', { id: '123' });
batchWrite.put('users', { name: 'jeff' });

and all of DocumentClient's features!

Installation

npm i @parana-games/tinymo

Setup

import { TinymoClient } from '@parana-games/tinymo';
const tinymo = TinymoClient.default();

Optionally, set your own DynamoDBClient:

TinymoClient.setDynamoDBClient(new DynamoDBClient({})); // Useful when using X-Ray!

Usage

Create requests through the client:

const put = tinymo.put('users', { id: '123', name: 'dan' });
const get = tinymo.get('games', { id: 'pool-stars' }).attributes('description');
const query = tinymo.query('users').keyBetween('sk', 'order#001', 'order#999');

Run requests:

await put.run()
const getResult = await get.run();
const queryResult = await query.run();

All tinymo requests are run-able, so you can do things like:

Promise.all([put, get, query].map(request => request.run()));

Testability

Use build() on any tinymo object to output pure DynamoDB JSON-based command inputs:

const put = tinymo.put('games', { name: 'pool-stars' });
put.build()

โ†“

{
  'TableName': 'games',
  'Item': {
    'name': 'pool-stars'
  }
}

Useful for tiny unit tests!

Usage without the tinymo client

You can also use build() when using your own DynamoDBClient:

import { Delete } from '@parana-games/tinymo';

const tinymoDelete = new Delete('users', { name: 'john' });
const command = new DeleteCommand(tinymoDelete.build());
const dynamoDBClient = new DynamoDBClient({});
await dynamoDBClient.send(command);

But when creating tinymo's objects using new, avoid using run()!

import { Scan } from '@parana-games/tinymo';

const scan = new Scan('users');
await scan.run(); // error thrown as this instance is clientless

Documentation

tinymo aligns strictly with DynamoDB's API, so you can simply refer to its documentation.

Contributing

If you think we've missed something or can do something better, feel free opening an issue or submitting a pull request.

tinymo's People

Contributors

dan-german 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.