aws-dynamodb-scala


License

License

Categories

Categories

Scala Languages AWS Container PaaS Providers
GroupId

GroupId

jp.co.bizreach
ArtifactId

ArtifactId

aws-dynamodb-scala_2.12
Last Version

Last Version

0.0.9
Release Date

Release Date

Type

Type

jar
Description

Description

aws-dynamodb-scala
aws-dynamodb-scala
Project URL

Project URL

https://github.com/bizreach/aws-dynamodb-scala
Project Organization

Project Organization

jp.co.bizreach
Source Code Management

Source Code Management

https://github.com/bizreach/aws-dynamodb-scala

Download aws-dynamodb-scala_2.12

How to add to project

<!-- https://jarcasting.com/artifacts/jp.co.bizreach/aws-dynamodb-scala_2.12/ -->
<dependency>
    <groupId>jp.co.bizreach</groupId>
    <artifactId>aws-dynamodb-scala_2.12</artifactId>
    <version>0.0.9</version>
</dependency>
// https://jarcasting.com/artifacts/jp.co.bizreach/aws-dynamodb-scala_2.12/
implementation 'jp.co.bizreach:aws-dynamodb-scala_2.12:0.0.9'
// https://jarcasting.com/artifacts/jp.co.bizreach/aws-dynamodb-scala_2.12/
implementation ("jp.co.bizreach:aws-dynamodb-scala_2.12:0.0.9")
'jp.co.bizreach:aws-dynamodb-scala_2.12:jar:0.0.9'
<dependency org="jp.co.bizreach" name="aws-dynamodb-scala_2.12" rev="0.0.9">
  <artifact name="aws-dynamodb-scala_2.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='jp.co.bizreach', module='aws-dynamodb-scala_2.12', version='0.0.9')
)
libraryDependencies += "jp.co.bizreach" % "aws-dynamodb-scala_2.12" % "0.0.9"
[jp.co.bizreach/aws-dynamodb-scala_2.12 "0.0.9"]

Dependencies

compile (3)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.8
org.scala-lang : scala-reflect jar 2.12.8
com.github.seratch : awscala_2.12 jar 0.8.2

test (1)

Group / Artifact Type Version
org.scalatest : scalatest_2.12 jar 3.0.7

Project Modules

There are no modules declared in this project.

aws-dynamodb-scala Build Status

Scala client for Amazon DynamoDB

How to use

Add a following dependency into your build.sbt at first.

libraryDependencies += "jp.co.bizreach" %% "aws-dynamodb-scala" % "0.0.9"

Then you can use aws-dynamodb-scala in your code.

import jp.co.bizreach.dynamodb4s._
import awscala.dynamodbv2.DynamoDB

// for local environment
implicit val db = DynamoDB.local()

// for AWS environment
implicit val db = DynamoDB.apply(accessKeyId = "xxx", secretAccessKey = "xxx")

Create table definition as below:

object Members extends DynamoTable {
  val table   = "members"
  val country = DynamoHashKey[String]("country")
  val id      = DynamoRangeKey[Int]("id")
  val name    = DynamoAttribute[String]("name")
  val age     = DynamoAttribute[Int]("age")
  val company = DynamoAttribute[String]("company")
}

// Case class is optional
case class Member(
  val country: String,
  val id: Int,
  val name: String,
  val age: Int,
  val company: Option[String]
)

Put

// Put by case class
Members.put(Member("Japan", 1, "Naoki Takezoe", 30, Some("BizReach")))

// Update only specified properties
Members.putAttributes("Japan", 1){ t =>
  t.name -> "Takako Shimamoto" :: t.age  -> 25 :: Nil
}

Query

// Query with case class mapping
val list: Seq[Member] = Members.query.filter { t =>
  t.country -> DynamoDBCondition.eq("Japan") :: t.id -> DynamoDBCondition.eq(1) :: Nil
}.list[Member]

// Query with manual mapping
val list: Seq[(String, Int)] = Members.query
  .select { t => t.name :: t.age :: Nil }
  .filter { t => t.country -> DynamoDBCondition.eq("Japan") :: t.id -> DynamoDBCondition.eq(1) :: Nil }
  .limit(100000)
  .map { (t, x) =>
    (x.get(t.name), x.get(t.age))
  }

Secondary index

object Members extends DynamoTable {
  val table   = "members"
  val id      = DynamoHashKey[Int]("id")
  val country = DynamoRangeKey[String]("country")
  val name    = DynamoAttribute[String]("name")
  val age     = DynamoAttribute[Int]("age")
  val company = DynamoAttribute[String]("company")
  object companyIndex extends DynamoTable.SecondaryIndex {
    val index   = "companyIndex"
    val country = DynamoHashKey[String]("country")
    val company = DynamoRangeKey[String]("company")
  }  
}

val list: Seq[Member] = Members.query.filter2(_.companyIndex){ t =>
  t.country -> DynamoDBCondition.eq("Japan") :: t.company -> DynamoDBCondition.eq("BizReach") :: Nil
}.list[Member]

Scan

Members.scan.filter("company = :company", "company" -> "BizReach").as[Member]{ x =>
  println(x)
}
jp.co.bizreach

BizReach,Inc.

Versions

Version
0.0.9
0.0.8
0.0.7
0.0.6
0.0.5