Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ on:
release:
types: [published]
push:
branches: main
branches:
- main
- update/sbt-exercise-0.7.1

jobs:
release:
Expand Down
26 changes: 20 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ ThisBuild / organization := "org.scala-exercises"
ThisBuild / githubOrganization := "47degrees"
ThisBuild / scalaVersion := "2.13.8"

// Required to prevent errors for eviction from binary incompatible dependency
// resolutions.
// See also: https://github.com/scala-exercises/exercises-cats/pull/267
ThisBuild / libraryDependencySchemes += "org.scala-lang.modules" %% "scala-xml" % "always"

resolvers ++= Seq(
"Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
Resolver.sbtPluginRepo("snapshots"),
Resolver.sbtPluginRepo("releases")
)

// This is required by the exercises compiler:
publishLocal := (publishLocal dependsOn compile).value
publishSigned := (publishSigned dependsOn compile).value
Expand All @@ -16,16 +27,19 @@ lazy val exercises = (project in file("."))
.settings(name := "exercises-doobie")
.settings(
libraryDependencies ++= Seq(
"org.scala-exercises" %% "exercise-compiler" % "0.6.7",
"org.scala-exercises" %% "definitions" % "0.6.7",
"org.scala-exercises" %% "exercise-compiler" % "0.7.1",
"org.scala-exercises" %% "definitions" % "0.7.1",
"org.typelevel" %% "cats-core" % "2.7.0",
"org.tpolecat" %% "doobie-core" % "0.13.4",
"org.tpolecat" %% "doobie-h2" % "0.13.4",
"org.tpolecat" %% "doobie-core" % "1.0.0-RC2",
"org.tpolecat" %% "doobie-h2" % "1.0.0-RC2",
"com.chuusai" %% "shapeless" % "2.3.7",
"org.scalatest" %% "scalatest" % "3.2.10",
"org.scalatest" %% "scalatest" % "3.2.11",
"org.scalacheck" %% "scalacheck" % "1.15.4",
"org.scalatestplus" %% "scalacheck-1-14" % "3.2.2.0",
"org.scalatestplus" %% "scalacheck-1-15" % "3.2.9.0",
"com.github.alexarchambault" %% "scalacheck-shapeless_1.15" % "1.3.0"
),
resolvers ++= Seq(
"Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
)
)
.enablePlugins(ExerciseCompilerPlugin)
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
addSbtPlugin("org.scala-exercises" % "sbt-exercise" % "0.6.7")
addSbtPlugin("org.scala-exercises" % "sbt-exercise" % "0.7.1")
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.10")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.2.24")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")
Expand Down
3 changes: 3 additions & 0 deletions src/main/scala/doobie/ConnectingToDatabaseSection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import doobie._
import org.scalaexercises.definitions.Section
import org.scalatest.matchers.should.Matchers
import org.scalatest.flatspec.AnyFlatSpec
import cats.effect.unsafe.IORuntime

/**
* ==Introduction==
Expand Down Expand Up @@ -112,6 +113,8 @@ import org.scalatest.flatspec.AnyFlatSpec
*/
object ConnectingToDatabaseSection extends AnyFlatSpec with Matchers with Section {

implicit val runtime: IORuntime = IORuntime.global

/**
* And here we go.
*/
Expand Down
5 changes: 1 addition & 4 deletions src/main/scala/doobie/DoobieUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,14 @@ import Model._

object DoobieUtils {

implicit val cs = IO.contextShift(ExecutionContexts.synchronous)

val transactor: Resource[IO, H2Transactor[IO]] = {
def url = "jdbc:h2:mem:"
val user = "sa"
val pass = ""

for {
ec <- ExecutionContexts.fixedThreadPool[IO](1)
bc <- Blocker[IO]
xa <- H2Transactor.newH2Transactor[IO](url, user, pass, ec, bc)
xa <- H2Transactor.newH2Transactor[IO](url, user, pass, ec)
} yield xa
}

Expand Down
5 changes: 4 additions & 1 deletion src/main/scala/doobie/ErrorHandlingSection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import doobie.implicits._
import org.scalaexercises.definitions.Section
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import cats.effect.unsafe.IORuntime

/**
* ==About Exceptions==
Expand Down Expand Up @@ -97,6 +98,8 @@ import org.scalatest.matchers.should.Matchers
*/
object ErrorHandlingSection extends AnyFlatSpec with Matchers with Section {

implicit val runtime: IORuntime = IORuntime.global

/**
* Let's do some exercises where errors will happen and see how to deal with them.
*
Expand Down Expand Up @@ -188,7 +191,7 @@ object ErrorHandlingSection extends AnyFlatSpec with Matchers with Section {

def safeInsert(name: String, age: Option[Int]): ConnectionIO[Long] =
insert(name, age)
.exceptSqlState { case UNIQUE_VIOLATION =>
.exceptSomeSqlState { case UNIQUE_VIOLATION =>
insert(name + "_20", age)
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/scala/doobie/MultiColumnQueriesSection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import shapeless._
import shapeless.record._
import cats.effect.unsafe.IORuntime

/**
* So far, we have constructed queries that return single-column results. These results were mapped
Expand Down Expand Up @@ -55,6 +56,8 @@ import shapeless.record._
*/
object MultiColumnQueriesSection extends AnyFlatSpec with Matchers with Section {

implicit val runtime: IORuntime = IORuntime.global

/**
* We can select multiple columns and map them to a tuple. The `gnp` column in our table is
* nullable so we’ll select that one into an `Option[Double]`.
Expand Down
3 changes: 3 additions & 0 deletions src/main/scala/doobie/ParameterizedQueriesSection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import ParameterizedQueryHelpers._
import org.scalaexercises.definitions.Section
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import cats.effect.unsafe.IORuntime

/**
* Previously we have worked with static SQL queries where the values used to filter data were
Expand Down Expand Up @@ -55,6 +56,8 @@ import org.scalatest.matchers.should.Matchers
*/
object ParameterizedQueriesSection extends AnyFlatSpec with Matchers with Section {

implicit val runtime: IORuntime = IORuntime.global

/**
* ==Adding a Parameter==
*
Expand Down
3 changes: 3 additions & 0 deletions src/main/scala/doobie/SelectingDataSection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import DoobieUtils.CountryTable._
import org.scalaexercises.definitions.Section
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import cats.effect.unsafe.IORuntime

/**
* We are going to construct some programs that retrieve data from the database and stream it back,
Expand Down Expand Up @@ -69,6 +70,8 @@ import org.scalatest.matchers.should.Matchers
*/
object SelectingDataSection extends AnyFlatSpec with Matchers with Section {

implicit val runtime: IORuntime = IORuntime.global

/**
* ==Getting info about the countries==
*
Expand Down
3 changes: 3 additions & 0 deletions src/main/scala/doobie/UpdatesSection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import UpdatesSectionHelpers.Person
import org.scalaexercises.definitions.Section
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import cats.effect.unsafe.IORuntime

/**
* In this section we examine operations that modify data in the database, and ways to retrieve the
Expand Down Expand Up @@ -75,6 +76,8 @@ import org.scalatest.matchers.should.Matchers
*/
object UpdatesSection extends AnyFlatSpec with Matchers with Section {

implicit val runtime: IORuntime = IORuntime.global

/**
* Let's insert a new row by using the recently defined `insert1` method.
*
Expand Down