Skip to content

Commit

Permalink
Merge branch 'master' into update/sbt-explicit-dependencies-0.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jczuchnowski authored Jul 27, 2023
2 parents fc65a08 + f7eb3a5 commit 6c8fcb8
Show file tree
Hide file tree
Showing 30 changed files with 195 additions and 109 deletions.
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Scala Steward: Reformat with scalafmt 3.7.10
9bcedec20a4fc7adedce8aea4921c05b0c7acfa4
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: CI

env:
JDK_JAVA_OPTIONS: -XX:+PrintCommandLineFlags -XX:+UseG1GC -Xmx4g -Xms4g
JVM_OPTS: -XX:+PrintCommandLineFlags -XX:+UseG1GC -Xmx4g -Xms4g
JDK_JAVA_OPTIONS: -XX:+PrintCommandLineFlags -XX:+UseG1GC -Xmx4g -Xms4g -Xss4m
JVM_OPTS: -XX:+PrintCommandLineFlags -XX:+UseG1GC -Xmx4g -Xms4g -Xss4m

on:
pull_request:
Expand Down Expand Up @@ -35,7 +35,7 @@ jobs:
fail-fast: false
matrix:
java: ['[email protected]', '[email protected]']
scala: ['2.12.17', '2.13.10']
scala: ['2.12.18', '2.13.10']
steps:
- name: Checkout current branch
uses: actions/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "3.5.9"
version = "3.7.11"
maxColumn = 120
align.preset = most
continuationIndent.defnSite = 2
Expand Down
41 changes: 27 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,12 @@ Values that will represent tables in DSL are then created by calling `defineTabl
In order for `defineTable` to work, user need to provide implicit `Schema` of data type.

```scala
import java.util.UUID
import zio.schema.DeriveSchema
import zio.sql.postgresql.PostgresJdbcModule
import zio.sql.table.Table._

import java.time._
import java.util.UUID

object Repository extends PostgresJdbcModule {
final case class Product(id: UUID, name: String, price: BigDecimal)
Expand Down Expand Up @@ -140,43 +143,43 @@ Using the previous example with `Product` and `Order` table
```scala
val (id, name, price) = products.columns

val (orderId, productId, quantity) = orders.columns
val (orderId, productId, quantity, date) = orders.columns
```

## Selects

Simple select.

```scala
val allProducts = select(productId, name, price).from(products)
val allProducts = select(id, name, price).from(products)
```

Using `where` clause.

```scala
def productById(id: UUID) =
select(productId, name, price).from(products).where(productId === id)
def productById(uuid: UUID) =
select(id, name, price).from(products).where(id === uuid)
```

Inner join.

```scala
val ordersWithProductNames =
select(orderId, name).from(products.join(orders).on(productId === fkProductId))
select(orderId, name).from(products.join(orders).on(productId === id))
```

Left outer join.

```scala
val leftOuter =
select(orderId, name).from(products.leftOuter(orders).on(productId === fkProductId))
select(orderId, name).from(products.leftOuter(orders).on(productId === id))
```

Right outer join.

```scala
val rightOuter =
select(orderId, name).from(products.rightOuter(orders).on(productId === fkProductId))
select(orderId, name).from(products.rightOuter(orders).on(productId === id))
```

Using `limit` and `offset`
Expand All @@ -185,26 +188,36 @@ Using `limit` and `offset`
val limitedResults =
select(orderId, name)
.from(products.join(orders)
.on(productId === fkProductId))
.on(productId === id))
.limit(5)
.offset(10)
```

## Inserts

```scala
insertInto(products)
(productId, name, price)
.values((UUID.randomUUID(), "Zionomicon", 10.5))
def insertProduct(uuid: UUID) =
insertInto(products)(id, name, price)
.values((uuid, "Zionomicon", 10.5))
```

## Updates

TODO: details
```scala
def updateProduct(uuid: UUID) =
update(products)
.set(name, "foo")
.set(price, price * 1.1)
.where(id === uuid)
```

## Deletes

TODO: details
```scala
def deleteProduct(uuid: UUID) =
deleteFrom(products)
.where(id === uuid)
```

## Transactions

Expand Down
10 changes: 5 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ addCommandAlias("fmtOnce", "all scalafmtSbt scalafmt test:scalafmt")
addCommandAlias("fmt", "fmtOnce;fmtOnce")
addCommandAlias("check", "all scalafmtSbtCheck scalafmtCheck test:scalafmtCheck")

val zioVersion = "2.0.6"
val zioSchemaVersion = "0.4.2"
val testcontainersVersion = "1.17.6"
val testcontainersScalaVersion = "0.40.11"
val logbackVersion = "1.2.11"
val zioVersion = "2.0.15"
val zioSchemaVersion = "0.4.13"
val testcontainersVersion = "1.18.3"
val testcontainersScalaVersion = "0.40.17"
val logbackVersion = "1.3.8"

lazy val root = project
.in(file("."))
Expand Down
26 changes: 0 additions & 26 deletions core/shared/src/test/scala/zio-sql/HelloWorldSpec.scala

This file was deleted.

41 changes: 27 additions & 14 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,12 @@ Values that will represent tables in DSL are then created by calling `defineTabl
In order for `defineTable` to work, user need to provide implicit `Schema` of data type.

```scala
import java.util.UUID
import zio.schema.DeriveSchema
import zio.sql.postgresql.PostgresJdbcModule
import zio.sql.table.Table._

import java.time._
import java.util.UUID

object Repository extends PostgresJdbcModule {
final case class Product(id: UUID, name: String, price: BigDecimal)
Expand Down Expand Up @@ -140,43 +143,43 @@ Using the previous example with `Product` and `Order` table
```scala
val (id, name, price) = products.columns

val (orderId, productId, quantity) = orders.columns
val (orderId, productId, quantity, date) = orders.columns
```

## Selects

Simple select.

```scala
val allProducts = select(productId, name, price).from(products)
val allProducts = select(id, name, price).from(products)
```

Using `where` clause.

```scala
def productById(id: UUID) =
select(productId, name, price).from(products).where(productId === id)
def productById(uuid: UUID) =
select(id, name, price).from(products).where(id === uuid)
```

Inner join.

```scala
val ordersWithProductNames =
select(orderId, name).from(products.join(orders).on(productId === fkProductId))
select(orderId, name).from(products.join(orders).on(productId === id))
```

Left outer join.

```scala
val leftOuter =
select(orderId, name).from(products.leftOuter(orders).on(productId === fkProductId))
select(orderId, name).from(products.leftOuter(orders).on(productId === id))
```

Right outer join.

```scala
val rightOuter =
select(orderId, name).from(products.rightOuter(orders).on(productId === fkProductId))
select(orderId, name).from(products.rightOuter(orders).on(productId === id))
```

Using `limit` and `offset`
Expand All @@ -185,26 +188,36 @@ Using `limit` and `offset`
val limitedResults =
select(orderId, name)
.from(products.join(orders)
.on(productId === fkProductId))
.on(productId === id))
.limit(5)
.offset(10)
```

## Inserts

```scala
insertInto(products)
(productId, name, price)
.values((UUID.randomUUID(), "Zionomicon", 10.5))
def insertProduct(uuid: UUID) =
insertInto(products)(id, name, price)
.values((uuid, "Zionomicon", 10.5))
```

## Updates

TODO: details
```scala
def updateProduct(uuid: UUID) =
update(products)
.set(name, "foo")
.set(price, price * 1.1)
.where(id === uuid)
```

## Deletes

TODO: details
```scala
def deleteProduct(uuid: UUID) =
deleteFrom(products)
.where(id === uuid)
```

## Transactions

Expand Down
1 change: 1 addition & 0 deletions jdbc/src/main/scala/zio/sql/JdbcInternalModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ trait JdbcInternalModule { self: Jdbc =>
else
try {
val value = decoder
if (resultSet.wasNull()) return Right(null.asInstanceOf[A])

value match {
case Some(value) => Right(value)
Expand Down
2 changes: 1 addition & 1 deletion macros/src/main/scala-2/zio/sql/macros/insertlike.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ object InsertLike {
F,
ColsRepr,
AllColumnIdentities,
Z,
Z
] = macro createInsertLikeImpl[F, ColsRepr, AllColumnIdentities, Z]

def createInsertLikeImpl[
Expand Down
7 changes: 3 additions & 4 deletions macros/src/main/scala-3/zio/sql/macros/groupbylike.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package zio.sql.macros


sealed trait GroupByLike[All, Grouped]

object GroupByLike {

final case class CanBeGrouped[All, Grouped]() extends GroupByLike[All, Grouped]
final case class CanBeGrouped[All, Grouped]() extends GroupByLike[All, Grouped]

implicit def createGroupByLike[All, Grouped]: GroupByLike[All, Grouped] = CanBeGrouped[All, Grouped]()
}
implicit def createGroupByLike[All, Grouped]: GroupByLike[All, Grouped] = CanBeGrouped[All, Grouped]()
}
7 changes: 4 additions & 3 deletions macros/src/main/scala-3/zio/sql/macros/havinglike.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package zio.sql.macros
package zio.sql.macros

sealed trait HavingIsSound[AllF, GroupByF, HavingF]

object HavingIsSound {

final case class HavingCanBeCalled[AllF, GroupByF, HavingF]() extends HavingIsSound[AllF, GroupByF, HavingF]

implicit def materializeHavingIsSound[AllF, GroupByF, HavingF]: HavingIsSound[AllF, GroupByF, HavingF] = HavingCanBeCalled[AllF, GroupByF, HavingF]()
implicit def materializeHavingIsSound[AllF, GroupByF, HavingF]: HavingIsSound[AllF, GroupByF, HavingF] =
HavingCanBeCalled[AllF, GroupByF, HavingF]()

}
}
2 changes: 1 addition & 1 deletion macros/src/main/scala-3/zio/sql/macros/insertlike.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ object InsertLike {
F,
ColsRepr,
AllColumnIdentities,
Z,
Z
] = CanBeInserted[F, ColsRepr, AllColumnIdentities, Z]()
}
3 changes: 1 addition & 2 deletions macros/src/main/scala-3/zio/sql/macros/normalizer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ object Normalizer {
// override type Out = Out2
// }

implicit def createNormalizer[In]: Normalizer[In] = {
implicit def createNormalizer[In]: Normalizer[In] =
new Normalizer[In] {}
}

}
11 changes: 5 additions & 6 deletions macros/src/main/scala-3/zio/sql/macros/notliteral.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package zio.sql.macros
package zio.sql.macros

sealed trait IsNotLiteral[F]

object IsNotLiteral {

final case class FIsNotLiteral[F]() extends IsNotLiteral[F]
final case class FIsNotLiteral[F]() extends IsNotLiteral[F]

implicit def materializeIsNotLiteral[F]: IsNotLiteral[F] = {
FIsNotLiteral[F]()
}
}
implicit def materializeIsNotLiteral[F]: IsNotLiteral[F] =
FIsNotLiteral[F]()
}
3 changes: 1 addition & 2 deletions macros/src/main/scala-3/zio/sql/macros/tablelike.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ object TableSchema {

final case class Compatible[T]() extends TableSchema[T]


implicit def materializeTableSchema[T]: TableSchema[T] = Compatible[T]()

}
}
Loading

0 comments on commit 6c8fcb8

Please sign in to comment.