Git Product home page Git Product logo

tiny-dynamo's Introduction

๐Ÿ“ฆ ๐Ÿค

tiny dynamo

A tinier, simpler, key-value focused interface for AWS DynamoDB

Install

To install tiny dynamo add the following to your Cargo.toml file.

[dependencies]
tiny-dynamo = "0.1"

Tiny what now?

Amazon DynamoDB is a key-value and document database that delivers single-digit millisecond performance at any scale.

This quote comes directly from the Amazon DynamoDB docs. This combinaton has some implications on its client APIs that are less than ideal for very simple key-value applications. These interfaces can be overly complicated and sometimes daunting for the uninitiated to say the least.

Tiny Dynamo aims to leverge the useful parts of DynamoDB, the performance and scalability, but expose a much smaller and simpler API that you might expect from a key-value database.

Usage

use std::{env, error::Error};
use tiny_dynamo::{reqwest_transport::Reqwest, Credentials, Table, DB};

fn main() -> Result<(), Box<dyn Error>> {
    let db = DB::new(
        Credentials::new(
            env::var("AWS_ACCESS_KEY_ID")?,
            env::var("AWS_SECRET_ACCESS_KEY")?,
        ),
        Table::new(
            "table-name",
            "key-attr-name",
            "value-attr-name",
            "us-east-1".parse()?,
            None
        ),
        Reqwest::new(),
    );

    println!("{:#?}", db.set("foo", "bar")?);
    println!("{:#?}", db.get("foo")?);

    Ok(())
}

A few notable differences when comparing Tiny Dynamo to traditional DynamoDB clients is that this client assumes a single table, a very common case for most DynamodbDB applications, so you configure your client with that table name so you don't need to redundantly provide it with each request.

You will also find the interface is reduced to get(key) set(key,value). This is intentional as this client is primarily focused on being a more comfortable fit for simple key-value applications.

Features

Tiny

Tiny Dynamo avoids packing carry-on luggage for anything you don't explicitly need for a simple key-value application. This includes an entire sdk and a transient line of dependencies. This allows it to fit more easily into smaller spaces and to deliver on Rust's zero cost promise of not paying for what you don't use.

Simpler Data Modeling

A common laborious activity with DynamoDB based applications figuring our your application's data model first and then translating that to a DynamoDB's key space design and catalog of item attribute types. This is fine and expected for applications that require more advanced query access patterns. For simple key-value applications, this is just tax. Tiny DynamoDB assumes a key-value data model.

Just the data plane

You can think of the DynamoDB API in terms of two planes: The data plane*cation cases, and the *control* plane, a set of APIs for provisioning the resources that will store your data. Combining these makes its surface area arbitrarily larger that it needs to be. Tiny Dynamo focuses on exposing just the data plane to retain a smaller surface area to learn.

Sans I/O

Tiny Dynamo takes a sans I/O library approach. It defines a Transport trait which allows for any I/O library to implement how requests are transfered over the wire by provides none without an explict cargo feature toggled on

Below are the current available cargo features

reqwest

the reqwest feature provides a reqwest_transport::Reqwest backend for sending requests, currently using a blocking client. An async feature is planned for the future

[dependencies]
tiny-dynamo = { version = "0.1", features = ["reqwest"]}

fastly

The fastly feature provides a fastly_transport::Fastly backend for sending requests suitable for Fastlys Compute@Edge platform

[dependencies]
tiny-dynamo = { version = "0.1", features = ["fastly"]}

BYOIO

If you would like to bring your own IO implementation you can define an implementation for a custom type

use tiny_dynamo::{Request, Transport};
use std::error::Error;

struct CustomIO;

impl Transport for CustomIO {
  fn send(&self, signed: Request) -> Result<(u16, String), Box<dyn Error>> {
    Ok(
      (200,"...".into())
    )
  }
}

Doug Tangren (softprops) 2021

tiny-dynamo's People

Contributors

softprops avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

mlafeldt

tiny-dynamo's Issues

consider a ttl feature

some usecases for kv stores involve a ttl. on keys. dynamodb supports this when you declare a number (N) typed attr as a ttl attribute in its table definition and with unix seconds value. dynamic ttls, those that vary by key, are less coming but static ttls, a duration applied to all keys so it makes sense to expose this as a TableInfo field with a Duration type.

a sketch

let db = DB::new(
  creds,
  TableInfo {
     ttl: ("column_name", Duration::from_secs(60))
     ...
  }
  requests
);

db.put("foo", "bar") // bar will be accessible for 60 seconds
db.get("foo"); // => Some("bar")
// time passes
db.get("foo"); // => None

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.