Skip to content

Commit

Permalink
draft zio-sbt integration, update existing docs
Browse files Browse the repository at this point in the history
  • Loading branch information
googley42 committed Aug 18, 2024
1 parent 6c21621 commit a9b0e83
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 23 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
[//]: # (So please do not edit it manually. Instead, change "docs/index.md" file or sbt setting keys)
[//]: # (e.g. "readmeDocumentation" and "readmeSupport".)

# ZIO DynamoDB
# ZIO Dynamodb

Simple, type-safe, and efficient access to DynamoDB

[![Development](https://img.shields.io/badge/Project%20Stage-Development-green.svg)](https://github.com/zio/zio/wiki/Project-Stages) ![CI Badge](https://github.com/zio/zio-dynamodb/workflows/CI/badge.svg) [![Sonatype Releases](https://img.shields.io/nexus/r/https/oss.sonatype.org/dev.zio/zio-dynamodb_2.13.svg?label=Sonatype%20Release)](https://oss.sonatype.org/content/repositories/releases/dev/zio/zio-dynamodb_2.13/) [![Sonatype Snapshots](https://img.shields.io/nexus/s/https/oss.sonatype.org/dev.zio/zio-dynamodb_2.13.svg?label=Sonatype%20Snapshot)](https://oss.sonatype.org/content/repositories/snapshots/dev/zio/zio-dynamodb_2.13/) [![javadoc](https://javadoc.io/badge2/dev.zio/zio-dynamodb-docs_2.13/javadoc.svg)](https://javadoc.io/doc/dev.zio/zio-dynamodb-docs_2.13) [![ZIO DynamoDB](https://img.shields.io/github/stars/zio/zio-dynamodb?style=social)](https://github.com/zio/zio-dynamodb)
[![Development](https://img.shields.io/badge/Project%20Stage-Development-green.svg)](https://github.com/zio/zio/wiki/Project-Stages) ![CI Badge](https://github.com/zio/zio-dynamodb/workflows/Continuous%20Integration/badge.svg) [![Sonatype Releases](https://img.shields.io/nexus/r/https/oss.sonatype.org/dev.zio/zio-dynamodb_2.13.svg?label=Sonatype%20Release)](https://oss.sonatype.org/content/repositories/releases/dev/zio/zio-dynamodb_2.13/) [![Sonatype Snapshots](https://img.shields.io/nexus/s/https/oss.sonatype.org/dev.zio/zio-dynamodb_2.13.svg?label=Sonatype%20Snapshot)](https://oss.sonatype.org/content/repositories/snapshots/dev/zio/zio-dynamodb_2.13/) [![javadoc](https://javadoc.io/badge2/dev.zio/zio-dynamodb-docs_2.13/javadoc.svg)](https://javadoc.io/doc/dev.zio/zio-dynamodb-docs_2.13) [![ZIO Dynamodb](https://img.shields.io/github/stars/zio/zio-dynamodb?style=social)](https://github.com/zio/zio-dynamodb)

## Introduction

Expand All @@ -18,11 +18,11 @@ For an overview of the High Level API please see the [ZIO DynamoDB cheat sheet](

## Installation

To use ZIO DynamoDB, we need to add the following line to our `build.sbt` file:
To use ZIO DynamoDB, we need to add the following lines to our `build.sbt` file:

```scala
libraryDependencies ++= Seq(
"dev.zio" %% "zio-dynamodb" "1.0.0-RC6"
"dev.zio" %% "zio-dynamodb" % "1.0.0-RC6"
)
```

Expand All @@ -36,7 +36,7 @@ libraryDependencies ++= Seq(
)
```

For CE interop examples please see [examples sbt module](examples/src/main/scala/zio/dynamodb/examples/dynamodblocal/interop/CeInteropExample.scala).
For CE interop examples please see [examples sbt module](https://github.com/zio/zio-dynamodb/blob/series/2.x/examples/src/main/scala/zio/dynamodb/examples/dynamodblocal/interop/CeInteropExample.scala).

### Read/write DynamoDB JSON
AWS tools like the CLI and Console read/write a special JSON representation of dynamoDB items. The new experimental optional `zio-dynamodb-json` module provides a way to read/write this form of JSON when working with both the High Level and Low Level API. To use this module, we need to also add the following line to our `build.sbt` file:
Expand All @@ -49,7 +49,7 @@ libraryDependencies ++= Seq(

## Example

For examples please see examples sbt module. Below is `Main.scala` from that module:
For examples please see [examples sbt module](https://github.com/zio/zio-dynamodb/tree/series/2.x/examples/src/main/scala/zio/dynamodb/examples). Below is `Main.scala` from that module:

```scala
import zio.aws.core.config
Expand Down Expand Up @@ -86,8 +86,8 @@ object Main extends ZIOAppDefault {
}
```

For examples on how to use the DynamoDBLocal in memory database please see the [integration tests](docs/../dynamodb/src/it/scala/zio/dynamodb/TypeSafeApiCrudSpec.scala)
and [DynamoDBLocalMain](docs/../examples/src/main/scala/zio/dynamodb/examples/dynamodblocal/DynamoDBLocalMain.scala) .
For examples on how to use the DynamoDBLocal in memory database please see the [integration tests](https://github.com/zio/zio-dynamodb/blob/series/2.x/dynamodb/src/it/scala/zio/dynamodb/TypeSafeApiCrudSpec.scala)
and [DynamoDBLocalMain](https://github.com/zio/zio-dynamodb/blob/series/2.x/examples/src/main/scala/zio/dynamodb/examples/dynamodblocal/DynamoDBLocalMain.scala) .
Note before you run these you must first run the DynamoDBLocal docker container using the provided docker-compose file:

```
Expand All @@ -106,15 +106,15 @@ docker compose -f docker/docker-compose.yml down

## Documentation

Learn more on the [ZIO DynamoDB homepage](https://zio.dev/zio-dynamodb/)!
Learn more on the [ZIO Dynamodb homepage](https://zio.dev/zio-dynamodb/)!

## Contributing

For the general guidelines, see ZIO [contributor's guide](https://zio.dev/about/contributing).
For the general guidelines, see ZIO [contributor's guide](https://zio.dev/contributor-guidelines).

## Code of Conduct

See the [Code of Conduct](https://zio.dev/about/code-of-conduct)
See the [Code of Conduct](https://zio.dev/code-of-conduct)

## Support

Expand Down
29 changes: 25 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ lazy val root =
project
.in(file("."))
.settings(skip in publish := true)
.aggregate(zioDynamodb, zioDynamodbCe, zioDynamodbJson, examples /*, docs */ )
.aggregate(zioDynamodb, zioDynamodbCe, zioDynamodbJson, examples, docs)

lazy val zioDynamodb = module("zio-dynamodb", "dynamodb")
.enablePlugins(BuildInfoPlugin)
Expand Down Expand Up @@ -330,16 +330,37 @@ def module(moduleName: String, fileName: String): Project =

lazy val docs = project
.in(file("zio-dynamodb-docs"))
.settings(stdSettings("zio-dynamodb-docs"))
.settings(
fork := false,
moduleName := "zio-dynamodb-docs",
scalacOptions -= "-Yno-imports",
scalacOptions -= "-Xfatal-warnings",
libraryDependencies ++= Seq("dev.zio" %% "zio" % zioVersion),
projectName := "ZIO DynamoDB",
mainModuleName := (zioDynamodb / moduleName).value,
projectStage := ProjectStage.Development,
ScalaUnidoc / unidoc / unidocProjectFilter := inProjects(zioDynamodb),
docsPublishBranch := "series/2.x"
ciWorkflowName := "Continuous Integration",
libraryDependencies ++= Seq("dev.zio" %% "zio" % zioVersion),
publish / skip := true,
mdocVariables ++= Map("ZIO_VERSION" -> zioVersion)
// docsPublishBranch := "series/2.x"
)
.dependsOn(zioDynamodb)
.dependsOn(zioDynamodb, zioDynamodbJson)
.enablePlugins(WebsitePlugin)

// lazy val docs = project
// .in(file("zio-dynamodb-docs"))
// .settings(
// moduleName := "zio-dynamodb-docs",
// scalacOptions -= "-Yno-imports",
// scalacOptions -= "-Xfatal-warnings",
// libraryDependencies ++= Seq("dev.zio" %% "zio" % zioVersion),
// projectName := "ZIO DynamoDB",
// mainModuleName := (zioDynamodb / moduleName).value,
// projectStage := ProjectStage.Development,
// ScalaUnidoc / unidoc / unidocProjectFilter := inProjects(zioDynamodb),
// docsPublishBranch := "series/2.x"
// )
// .dependsOn(zioDynamodb)
// .enablePlugins(WebsitePlugin)
10 changes: 7 additions & 3 deletions docs/cheat-sheet.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
id: cheat-sheet
title: "High Level API Cheat Sheet"
---

# High Level API Cheat Sheet

Note this guide assumes the reader has some basic knowledge of [AWS DynamoDB API](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.CoreComponents.html).
Expand Down Expand Up @@ -39,6 +44,5 @@ For more detailed working examples please see the High Level API integration tes
| [BatchGetItem](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchGetItem.html) | `people <- DynamoDBQuery.forEach(listOfIds)(id => DynamoDBQuery.get[Person]("personTable")(Person.id.partitionKey === id)).execute`|
| [BatchWriteItem](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchWriteItem.html) | _ <- `DynamoDBQuery.forEach(people)(p => put("personTable", p)).execute` |
| | |
| [TransactGetItems](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_TransactGetItems.html) | `val getJohn = get("personTable")(Person.id.partitionKey === "1")`<br>`val getSmith = get("employeeTable")(Employee.id.partitionKey === "2")`<br>`tuple <- (getJohn zip getSmith).transaction.execute` <br> Note transactions can span different tables. Also see the [transactions page](transactions.md). |
| [TransactWriteItems](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_TransactWriteItems.html) | `val putJohn = put("personTable", Person(1, "John", 2020))`<br>`val putSmith = put("employeeTable", Person(2, "Smith", 2024))`<br>`_ <- (putJohn zip putSmith).transaction.execute` <br> Note transactions can span different tables. Also see the [transactions page](transactions.md). |

| [TransactGetItems](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_TransactGetItems.html) | `tuple <- (get("personTable")(Person.id.partitionKey === "1") zip get("employeeTable")(Employee.id.partitionKey === "2")).transaction.execute` Note transactions can span different tables. Also see the [transactions page](transactions.md). |
| [TransactWriteItems](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_TransactWriteItems.html) | `_ <- (put("personTable", Person(1, "John", 2020)) zip put("employeeTable", Person(2, "Smith", 2024))).transaction.execute` Note transactions can span different tables. Also see the [transactions page](transactions.md). |
40 changes: 37 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ ZIO DynamoDB is a library that is used for type-safe, efficient, and boilerplate

Under the hood we use the excellent [ZIO AWS](https://zio.dev/zio-aws) library for type-safe DynamoDB access, and the awesome [ZIO Schema](https://zio.dev/zio-schema) library for schema derived codecs (see here for documentation on how to [customise these through annotations](codec-customization.md)).

For an overview of the High Level API please see the [ZIO DynamoDB cheat sheet](cheat-sheet.md).

## Installation

To use ZIO DynamoDB, we need to add the following lines to our `build.sbt` file:
Expand All @@ -24,9 +26,30 @@ libraryDependencies ++= Seq(
)
```

### Cats Effect Interop

To use the new Cats Effect 3 interop module, we need to also add the following line to our `build.sbt` file:

```scala
libraryDependencies ++= Seq(
"dev.zio" %% "zio-dynamodb-ce" "@VERSION@"
)
```

For CE interop examples please see [examples sbt module](https://github.com/zio/zio-dynamodb/blob/series/2.x/examples/src/main/scala/zio/dynamodb/examples/dynamodblocal/interop/CeInteropExample.scala).

### Read/write DynamoDB JSON
AWS tools like the CLI and Console read/write a special JSON representation of dynamoDB items. The new experimental optional `zio-dynamodb-json` module provides a way to read/write this form of JSON when working with both the High Level and Low Level API. To use this module, we need to also add the following line to our `build.sbt` file:

```scala
libraryDependencies ++= Seq(
"dev.zio" %% "zio-dynamodb-json" "@VERSION@"
)
```

## Example

For examples please see [examples sbt module](../examples/src/main/scala/zio/dynamodb/examples). Below is `Main.scala` from that module:
For examples please see [examples sbt module](https://github.com/zio/zio-dynamodb/tree/series/2.x/examples/src/main/scala/zio/dynamodb/examples). Below is `Main.scala` from that module:

```scala
import zio.aws.core.config
Expand Down Expand Up @@ -63,8 +86,19 @@ object Main extends ZIOAppDefault {
}
```

For examples on how to use the DynamoDBLocal in memory database please see the [integration tests](../dynamodb/src/it/scala/zio/dynamodb/LiveSpec.scala)
and [StudentZioDynamoDbExample](../examples/src/main/scala/zio/dynamodb/examples/dynamodblocal/StudentZioDynamoDbExample.scala)
For examples on how to use the DynamoDBLocal in memory database please see the [integration tests](https://github.com/zio/zio-dynamodb/blob/series/2.x/dynamodb/src/it/scala/zio/dynamodb/TypeSafeApiCrudSpec.scala)
and [DynamoDBLocalMain](https://github.com/zio/zio-dynamodb/blob/series/2.x/examples/src/main/scala/zio/dynamodb/examples/dynamodblocal/DynamoDBLocalMain.scala) .
Note before you run these you must first run the DynamoDBLocal docker container using the provided docker-compose file:

```
docker compose -f docker/docker-compose.yml up -d
```

Don't forget to shut down the container after you have finished

```
docker compose -f docker/docker-compose.yml down
```

## Resources
- [Introducing ZIO DynamoDB by Avinder Bahra & Adam Johnson](https://www.youtube.com/watch?v=f68-69eA8Vc&t=33s) - DynamoDB powers many cloud-scale applications, with its robust horizontal scalability and uptime. Yet, interacting with the Java SDK is error-prone and tedious. In this presentation, Avinder Bahra presents ZIO DynamoDB, a new library by Avi and Adam Johnson designed to make interacting with DynamoDB easy, type-safe, testable, and productive.
Expand Down
3 changes: 2 additions & 1 deletion docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ const sidebars = {
label: "ZIO DynamoDB",
collapsed: false,
link: { type: "doc", id: "index" },
items: [
items: [
"getting-started",
"cheat-sheet",
"codec-customization",
"transactions",
]
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.12.0")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.1.0")
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.6.0")
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.12")
addSbtPlugin("dev.zio" % "zio-sbt-website" % "0.3.10")
addSbtPlugin("dev.zio" % "zio-sbt-website" % "0.4.0-alpha.28")

0 comments on commit a9b0e83

Please sign in to comment.