Giter Site home page Giter Site logo

jpzk / bottledynamo Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 17 KB

Good enough AWS DynamoDB abstraction in Scala with Circe JSON serialization using Twitter Futures

License: Apache License 2.0

Scala 100.00%
dynamodb json circe finagle persistence nosql kv

bottledynamo's Introduction

bottledynamo

Build Status Codacy Badge codecov License GitHub stars

Bottle Dynamo is a good enough DynamoDB wrapper for putting and getting case classes in Scala. It uses Twitter's Futures and Circe as JSON serialization. Current features include:

  • In-Memory backend and DynamoDB
  • Support for exact-match get
  • Support for range queries (numbers as range key)

Dependency

Bottle Dynamo depends on Twitter Util Core (for futures), and on the AWS Java SDK DynamoDB (pullled in). Bottle Dynamo is available on Maven Central Repositories.

val bottledynamo = "com.madewithtea" %% "bottledynamo" % "1.0.0"

In-Memory (for tests)

import com.madewithtea.bottledynamo.{Store, Table, InMemoryKVImpl}
import io.circe.generic.auto._

case class SomeClass(field: String, number: Int)

val store = storeForKV(new InMemoryKVImpl)
val table = store.table[SomeClass]("sometable")

val entry = for { 
  _ <- table.create
  _ <- table.put("PK")(SomeClass("value",2)))
} yield table.get("PK")

Await.result(entry)

DynamoDB

import com.madewithtea.bottledynamo.{Store, Table, KV, DynamoDB, InMemoryKVImpl}
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB

val client = AmazonDynamoDBClientBuilder.standard()
      .withRegion(Regions.EU_CENTRAL_1)
      .build()

val store = storeForKV(new DynamoDB(client))
val table = store.table[SomeClass]("sometable")

val entry = for { 
  _ <- table.create
  _ <- table.put("PK")(SomeClass("value",2)))
} yield table.get("PK")

Await.result(entry)

DynamoDB and Range Tables

Create a table with DynamoDB interface first.

import com.madewithtea.bottledynamo.{Store, Table, KV, DynamoDB, InMemoryKVImpl}
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB

val client = AmazonDynamoDBClientBuilder.standard()
      .withRegion(Regions.EU_CENTRAL_1)
      .build()

val store = storeForKV(new DynamoDB(client))
val table = store.table[SomeClass]("sometable")

val entry = for { 
  _ <- table.put("PK", 10000)(SomeClass("value",2)))
} yield table.get("PK",10000)

Await.result(entry)

DynamoDB and Range Queries

Create a table with DynamoDB interface first

import com.madewithtea.bottledynamo.{Store, Table, KV, DynamoDB, InMemoryKVImpl}
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB

val client = AmazonDynamoDBClientBuilder.standard()
      .withRegion(Regions.EU_CENTRAL_1)
      .build()

val store = storeForKV(new DynamoDB(client))
val table = store.table[SomeClass]("sometable")

val entries = for { 
  _ <- table.put("PK", 10000)(SomeClass("value",2)))
  _ <- table.put("PK", 20000)(SomeClass("value",2)))
} yield table.query("PK",Some(0), Some(30000))

Await.result(entries)

bottledynamo's People

Contributors

jpzk avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  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.