Skip to content

Commit

Permalink
Merge branch 'main' into update/scala-library-2.12.20
Browse files Browse the repository at this point in the history
  • Loading branch information
jatcwang authored Dec 4, 2024
2 parents 7fb3845 + bb6ebdf commit aa9c20b
Show file tree
Hide file tree
Showing 28 changed files with 508 additions and 157 deletions.
15 changes: 6 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ jobs:
timeout-minutes: 60
steps:
- name: Install sbt
if: contains(runner.os, 'macos')
run: brew install sbt
uses: sbt/setup-sbt@v1

- name: Checkout current branch (full)
uses: actions/checkout@v4
Expand Down Expand Up @@ -82,8 +81,8 @@ jobs:
- name: Check there are no uncommitted changes in git (to catch generated files that weren't committed)
run: sbt '++ ${{ matrix.scala }}' checkGitNoUncommittedChanges

- name: Check Doc Site (2.13.14 only)
if: matrix.scala == '2.13.14'
- name: Check Doc Site (2.13.15 only)
if: matrix.scala == '2.13.15'
run: sbt '++ ${{ matrix.scala }}' docs/makeSite

- name: Make target directories
Expand Down Expand Up @@ -112,8 +111,7 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Install sbt
if: contains(runner.os, 'macos')
run: brew install sbt
uses: sbt/setup-sbt@v1

- name: Checkout current branch (full)
uses: actions/checkout@v4
Expand Down Expand Up @@ -189,16 +187,15 @@ jobs:

dependency-submission:
name: Submit Dependencies
if: github.event_name != 'pull_request'
if: github.event.repository.fork == false && github.event_name != 'pull_request'
strategy:
matrix:
os: [ubuntu-latest]
java: [temurin@11]
runs-on: ${{ matrix.os }}
steps:
- name: Install sbt
if: contains(runner.os, 'macos')
run: brew install sbt
uses: sbt/setup-sbt@v1

- name: Checkout current branch (full)
uses: actions/checkout@v4
Expand Down
20 changes: 12 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,27 @@ Running the tests or building the documentation site requires connection to the
which you can spin up using docker-compose:

```
docker-compose up -d --force-update
docker compose up -d --force-recreate
```

After that, in SBT you can run `test` to run tests, and `makeSite` to build the doc site
Note: If you're using Apple Silicone Macbooks (M1, M2, etc), you need to enable "Use Rosetta for x86_64/amd64 emulation on Apple Silicon" since there is no ARM64 image for postgis yet.

If you're editing code generation related code, you should reload the SBT project and then run the `freeGen2` SBT task
before compiling or running tests.
With the containers started, SBT you can run `test` to run tests, and `makeSite` to build the doc site.

## Fixing warnings

To improve code quality and bug, we enable many stricter scala compiler flags via the
[sbt-tpolecat](https://github.com/typelevel/sbt-tpolecat) plugin and in CI all warnings will be treated as errors.

For a more pleasant development experience, we default to `tpolecatDevMode` so warnings do not cause compilation errors.
You can use the sbt command `tpolecatCiMode` to enable strict mode and help catch any warnings you missed.

## Caveats when working on the code

## Avoiding internal cyclic module dependencies

For end users, doobie provides the aliases for high and low level APIs
such as `doobie.hi.HC`, `doobie.free.FPS`.
such as `doobie.hi.HC`, `doobie.free.FPS`.
Due to how the module depends on one another, internally in doobie we cannot use
these aliases because it'll lead to cyclic module dependencies and cause runtime errors.

Expand Down Expand Up @@ -49,6 +56,3 @@ To update the doc site, check out the tag first.
git checkout v1.2.3
sbt docs/publishMicrosite
```



14 changes: 7 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ import org.typelevel.sbt.tpolecat.{DevMode, CiMode}

// Library versions all in one place, for convenience and sanity.
lazy val catsVersion = "2.12.0"
lazy val catsEffectVersion = "3.5.4"
lazy val circeVersion = "0.14.7"
lazy val catsEffectVersion = "3.5.6"
lazy val circeVersion = "0.14.10"
lazy val fs2Version = "3.11.0"
lazy val h2Version = "1.4.200"
lazy val hikariVersion = "5.1.0" // N.B. Hikari v4 introduces a breaking change via slf4j v2
lazy val hikariVersion = "6.2.1" // N.B. Hikari v4 introduces a breaking change via slf4j v2
lazy val kindProjectorVersion = "0.11.2"
lazy val mysqlVersion = "9.0.0"
lazy val mysqlVersion = "9.1.0"
lazy val log4catsVersion = "2.7.0"
lazy val postGisVersion = "2024.1.0"
lazy val postgresVersion = "42.7.4"
lazy val refinedVersion = "0.11.2"
lazy val scalaCheckVersion = "1.15.4"
lazy val scalatestVersion = "3.2.18"
lazy val munitVersion = "1.0.0-RC1"
lazy val munitVersion = "1.0.2"
lazy val shapelessVersion = "2.3.12"
lazy val silencerVersion = "1.7.1"
lazy val specs2Version = "4.20.7"
lazy val scala212Version = "2.12.20"
lazy val scala213Version = "2.13.14"
lazy val scala3Version = "3.3.3"
lazy val scala213Version = "2.13.15"
lazy val scala3Version = "3.3.4"
// scala-steward:off
lazy val slf4jVersion = "1.7.36"
// scala-steward:on
Expand Down
5 changes: 2 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3.1'
version: "3.1"

services:
postgres:
Expand All @@ -16,9 +16,8 @@ services:
limits:
memory: 500M


mysql:
image: mysql:8.0-debian
image: mysql:8.0
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: world
Expand Down
11 changes: 4 additions & 7 deletions modules/core/src/main/scala-2/doobie/util/GetPlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,20 @@

package doobie.util

import shapeless._
import shapeless.*
import shapeless.ops.hlist.IsHCons

trait GetPlatform {
import doobie.util.compat.=:=

/** @group Instances */
implicit def unaryProductGet[A, L <: HList, H, T <: HList](
@deprecated("Use Get.derived instead to derive instances explicitly", "1.0.0-RC6")
def unaryProductGet[A, L <: HList, H, T <: HList](
implicit
G: Generic.Aux[A, L],
C: IsHCons.Aux[L, H, T],
H: Lazy[Get[H]],
E: (H :: HNil) =:= L
): MkGet[A] = {
void(C) // C drives inference but is not used directly
val get = H.value.tmap[A](h => G.from(h :: HNil))
MkGet.lift(get)
}
): MkGet[A] = MkGet.unaryProductGet

}
26 changes: 26 additions & 0 deletions modules/core/src/main/scala-2/doobie/util/MkGetPlatform.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2013-2020 Rob Norris and Contributors
// This software is licensed under the MIT License (MIT).
// For more information see LICENSE or https://opensource.org/licenses/MIT

package doobie.util

import shapeless._
import shapeless.ops.hlist.IsHCons

trait MkGetPlatform {
import doobie.util.compat.=:=

/** @group Instances */
implicit def unaryProductGet[A, L <: HList, H, T <: HList](
implicit
G: Generic.Aux[A, L],
C: IsHCons.Aux[L, H, T],
H: Lazy[Get[H]],
E: (H :: HNil) =:= L
): MkGet[A] = {
void(C) // C drives inference but is not used directly
val get = H.value.tmap[A](h => G.from(h :: HNil))
MkGet.lift(get)
}

}
26 changes: 26 additions & 0 deletions modules/core/src/main/scala-2/doobie/util/MkPutPlatform.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2013-2020 Rob Norris and Contributors
// This software is licensed under the MIT License (MIT).
// For more information see LICENSE or https://opensource.org/licenses/MIT

package doobie.util

import shapeless._
import shapeless.ops.hlist.IsHCons

trait MkPutPlatform {
import doobie.util.compat.=:=

/** @group Instances */
implicit def unaryProductPut[A, L <: HList, H, T <: HList](
implicit
G: Generic.Aux[A, L],
C: IsHCons.Aux[L, H, T],
H: Lazy[Put[H]],
E: (H :: HNil) =:= L
): MkPut[A] = {
void(E) // E is a necessary constraint but isn't used directly
val put = H.value.contramap[A](a => G.to(a).head)
MkPut.lift(put)
}

}
11 changes: 4 additions & 7 deletions modules/core/src/main/scala-2/doobie/util/PutPlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,20 @@

package doobie.util

import shapeless._
import shapeless.*
import shapeless.ops.hlist.IsHCons

trait PutPlatform {
import doobie.util.compat.=:=

/** @group Instances */
implicit def unaryProductPut[A, L <: HList, H, T <: HList](
@deprecated("Use Put.derived instead to derive instances explicitly", "1.0.0-RC6")
def unaryProductPut[A, L <: HList, H, T <: HList](
implicit
G: Generic.Aux[A, L],
C: IsHCons.Aux[L, H, T],
H: Lazy[Put[H]],
E: (H :: HNil) =:= L
): MkPut[A] = {
void(E) // E is a necessary constraint but isn't used directly
val put = H.value.contramap[A](a => G.to(a).head)
MkPut.lift(put)
}
): MkPut[A] = MkPut.unaryProductPut

}
3 changes: 3 additions & 0 deletions modules/core/src/main/scala-2/doobie/util/ReadPlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ trait ReadPlatform {
MkRead.ogeneric[A, Repr]
}

@deprecated("Use Read.derived instead to derive instances explicitly", "1.0.0-RC6")
def generic[T, Repr](implicit gen: Generic.Aux[T, Repr], G: Lazy[MkRead[Repr]]): MkRead[T] =
MkRead.generic[T, Repr]
}
4 changes: 4 additions & 0 deletions modules/core/src/main/scala-2/doobie/util/WritePlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ trait WritePlatform {
val _ = isTuple
MkWrite.ogeneric[A, Repr]
}

@deprecated("Use Write.derived instead to derive instances explicitly", "1.0.0-RC6")
def generic[T, Repr](implicit gen: Generic.Aux[T, Repr], A: Lazy[MkWrite[Repr]]): MkWrite[T] =
MkWrite.generic[T, Repr]
}
15 changes: 1 addition & 14 deletions modules/core/src/main/scala-3/doobie/util/GetPlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,4 @@

package doobie.util

import scala.deriving.Mirror

trait GetPlatform:

// Get is available for single-element products.
given x[P <: Product, A](
using
p: Mirror.ProductOf[P],
i: p.MirroredElemTypes =:= (A *: EmptyTuple),
g: Get[A]
): MkGet[P] = {
val get = g.map(a => p.fromProduct(a *: EmptyTuple))
MkGet.lift(get)
}
trait GetPlatform {}
20 changes: 20 additions & 0 deletions modules/core/src/main/scala-3/doobie/util/MkGetPlatform.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) 2013-2020 Rob Norris and Contributors
// This software is licensed under the MIT License (MIT).
// For more information see LICENSE or https://opensource.org/licenses/MIT

package doobie.util

import scala.deriving.Mirror

trait MkGetPlatform:

// Get is available for single-element products.
given unaryProductGet[P <: Product, A](
using
p: Mirror.ProductOf[P],
i: p.MirroredElemTypes =:= (A *: EmptyTuple),
g: Get[A]
): MkGet[P] = {
val get = g.map(a => p.fromProduct(a *: EmptyTuple))
MkGet.lift(get)
}
20 changes: 20 additions & 0 deletions modules/core/src/main/scala-3/doobie/util/MkPutPlatform.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) 2013-2020 Rob Norris and Contributors
// This software is licensed under the MIT License (MIT).
// For more information see LICENSE or https://opensource.org/licenses/MIT

package doobie.util

import scala.deriving.Mirror

trait MkPutPlatform:

// Put is available for single-element products.
given unaryProductPut[P <: Product, A](
using
m: Mirror.ProductOf[P],
i: m.MirroredElemTypes =:= (A *: EmptyTuple),
p: Put[A]
): MkPut[P] = {
val put: Put[P] = p.contramap(p => i(Tuple.fromProductTyped(p)).head)
MkPut.lift(put)
}
15 changes: 1 addition & 14 deletions modules/core/src/main/scala-3/doobie/util/PutPlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,4 @@

package doobie.util

import scala.deriving.Mirror

trait PutPlatform:

// Put is available for single-element products.
given [P <: Product, A](
using
m: Mirror.ProductOf[P],
i: m.MirroredElemTypes =:= (A *: EmptyTuple),
p: Put[A]
): MkPut[P] = {
val put: Put[P] = p.contramap(p => i(Tuple.fromProductTyped(p)).head)
MkPut.lift(put)
}
trait PutPlatform {}
12 changes: 10 additions & 2 deletions modules/core/src/main/scala/doobie/syntax/stream.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,24 @@ import doobie.util.compat.=:=
import doobie.util.transactor.Transactor
import doobie.free.connection.ConnectionIO
import cats.data.Kleisli
import cats.effect.Concurrent
import cats.effect.kernel.{Async, MonadCancelThrow}
import fs2.{Pipe, Stream}

class StreamOps[F[_], A](fa: Stream[F, A]) {
def transact[M[_]: MonadCancelThrow](xa: Transactor[M])(implicit
def transactNoPrefetch[M[_]: MonadCancelThrow](xa: Transactor[M])(implicit
ev: Stream[F, A] =:= Stream[ConnectionIO, A]
): Stream[M, A] = xa.transP.apply(fa)

def transact[M[_]: Concurrent](xa: Transactor[M])(implicit
ev: Stream[F, A] =:= Stream[ConnectionIO, A]
): Stream[M, A] = transactNoPrefetch(xa).prefetchN(1)

}
class KleisliStreamOps[A, B](fa: Stream[Kleisli[ConnectionIO, A, *], B]) {
def transact[M[_]: MonadCancelThrow](xa: Transactor[M]): Stream[Kleisli[M, A, *], B] = xa.transPK[A].apply(fa)
def transactNoPrefetch[M[_]: MonadCancelThrow](xa: Transactor[M]): Stream[Kleisli[M, A, *], B] =
xa.transPK[A].apply(fa)
def transact[M[_]: Concurrent](xa: Transactor[M]): Stream[Kleisli[M, A, *], B] = transactNoPrefetch(xa).prefetchN(1)
}
class PipeOps[F[_], A, B](inner: Pipe[F, A, B]) {
def transact[M[_]: Async](xa: Transactor[M])(implicit ev: Pipe[F, A, B] =:= Pipe[ConnectionIO, A, B]): Pipe[M, A, B] =
Expand Down
Loading

0 comments on commit aa9c20b

Please sign in to comment.