From bd6853866cebfdc371fbce48f0270fb098c5d85e Mon Sep 17 00:00:00 2001 From: franciscodr Date: Thu, 14 Jul 2016 16:25:09 +0200 Subject: [PATCH] Fixes conflict between different doobie versions --- build.sbt | 7 ++++--- .../scala/doobie/ConnectingToDatabaseSection.scala | 14 +++----------- src/main/scala/doobie/DoobieUtils.scala | 14 ++++++++++---- src/main/scala/doobie/Model.scala | 12 ++++++------ src/main/scala/doobie/SelectingDataSection.scala | 8 -------- .../doobie/SelectingDataSectionSpec.scala | 3 +-- 6 files changed, 24 insertions(+), 34 deletions(-) rename src/test/scala/{exercises => }/doobie/SelectingDataSectionSpec.scala (95%) diff --git a/build.sbt b/build.sbt index 240b14a..4d1e2ee 100644 --- a/build.sbt +++ b/build.sbt @@ -4,7 +4,8 @@ lazy val doobie = (project in file(".")) .settings( organization := "org.scala-exercises", name := "exercises-doobie", - scalaVersion := "2.11.7", + scalaVersion := "2.11.8", + parallelExecution in Test := false, version := "0.2.2-SNAPSHOT", resolvers ++= Seq( Resolver.sonatypeRepo("snapshots"), @@ -16,8 +17,8 @@ lazy val doobie = (project in file(".")) "org.scala-exercises" %% "definitions" % version.value, "org.scalacheck" %% "scalacheck" % "1.12.5", "com.github.alexarchambault" %% "scalacheck-shapeless_1.12" % "0.3.1", - "org.tpolecat" %% "doobie-core" % "0.3.0", - "org.tpolecat" %% "doobie-contrib-h2" % "0.3.0", + "org.tpolecat" %% "doobie-core" % "0.2.3", + "org.tpolecat" %% "doobie-contrib-h2" % "0.2.3", compilerPlugin("org.spire-math" %% "kind-projector" % "0.7.1") ) ) diff --git a/src/main/scala/doobie/ConnectingToDatabaseSection.scala b/src/main/scala/doobie/ConnectingToDatabaseSection.scala index b23dade..9ec2800 100644 --- a/src/main/scala/doobie/ConnectingToDatabaseSection.scala +++ b/src/main/scala/doobie/ConnectingToDatabaseSection.scala @@ -1,13 +1,12 @@ package doobie -import org.scalatest._ +import doobie.DoobieUtils._ import doobie.imports._ import org.scalaexercises.definitions.Section +import org.scalatest._ +import scalaz.Scalaz._ import scalaz._ -import Scalaz._ -import scala.util.Random -import scalaz.concurrent.Task /** ==Introduction== * doobie is a monadic API that provides a number of data types that all work the same way @@ -60,13 +59,6 @@ import scalaz.concurrent.Task */ object ConnectingToDatabaseSection extends FlatSpec with Matchers with Section { - val xa = DriverManagerTransactor[Task]( - driver = "org.h2.Driver", - url = s"jdbc:h2:mem:doobie-exercises-${Random.nextFloat()};DB_CLOSE_DELAY=-1;MODE=PostgreSQL", - user = "sa", - pass = "" - ) - /** * Right, so let’s do this. */ diff --git a/src/main/scala/doobie/DoobieUtils.scala b/src/main/scala/doobie/DoobieUtils.scala index f06c39c..3420b4a 100644 --- a/src/main/scala/doobie/DoobieUtils.scala +++ b/src/main/scala/doobie/DoobieUtils.scala @@ -2,7 +2,7 @@ package doobie import java.util.UUID -import doobie.Model.Country +import doobie.Model._ import doobie.imports._ import scalaz.concurrent.Task @@ -17,7 +17,7 @@ object DoobieUtils { pass = "" ) - val createCountryTable: ConnectionIO[Int] = { + val createCountryTable: ConnectionIO[Int] = sql""" CREATE TABLE IF NOT EXISTS country ( code VARCHAR(64), @@ -26,10 +26,16 @@ object DoobieUtils { gnp DECIMAL(10,2) ) """.update.run - } val dropCountryTable: ConnectionIO[Int] = sql"""DROP TABLE IF EXISTS country""".update.run def insertCountries(countries: List[Country]): ConnectionIO[Int] = - Update[Country]("insert into country (code, name, population, gnp) values (?,?,?,?)").updateMany(countries) + Update[Country](s"insert into country (code, name, population, gnp) values (?,?,?,?)").updateMany(countries) + + val initializeData = for { + _ <- createCountryTable + _ <- insertCountries(countries) + } yield Unit + + val cleanupData = dropCountryTable } diff --git a/src/main/scala/doobie/Model.scala b/src/main/scala/doobie/Model.scala index 46f4f2d..2c4ada1 100644 --- a/src/main/scala/doobie/Model.scala +++ b/src/main/scala/doobie/Model.scala @@ -2,13 +2,13 @@ package doobie object Model { - case class Country(code: String, name: String, population: Long, gnp: Double) + case class Country(code: String, name: String, population: Long, gnp: Option[Double]) val countries = List( - Country("DEU", "Germany", 82164700, 2133367.00), - Country("ESP", "Spain", 39441700, 553223.00), - Country("FRA", "France", 59225700, 1424285.00), - Country("GBR", "United Kingdom", 59623400, 1378330.00), - Country("USA", "United States of America", 278357000, 8510700.00) + Country("DEU", "Germany", 82164700, Option(2133367.00)), + Country("ESP", "Spain", 39441700, Option(553223.00)), + Country("FRA", "France", 59225700, Option(1424285.00)), + Country("GBR", "United Kingdom", 59623400, Option(1378330.00)), + Country("USA", "United States of America", 278357000, Option(8510700.00)) ) } diff --git a/src/main/scala/doobie/SelectingDataSection.scala b/src/main/scala/doobie/SelectingDataSection.scala index b2569ac..bbd15b2 100644 --- a/src/main/scala/doobie/SelectingDataSection.scala +++ b/src/main/scala/doobie/SelectingDataSection.scala @@ -1,7 +1,6 @@ package doobie import doobie.DoobieUtils._ -import doobie.Model._ import doobie.imports._ import org.scalaexercises.definitions.Section import org.scalatest.{FlatSpec, Matchers} @@ -59,13 +58,6 @@ import org.scalatest.{FlatSpec, Matchers} */ object SelectingDataSection extends FlatSpec with Matchers with Section { - val initializeData = for { - _ <- createCountryTable - _ <- insertCountries(countries) - } yield Unit - - val cleanupData = dropCountryTable - /** * == Getting info about the countries == * diff --git a/src/test/scala/exercises/doobie/SelectingDataSectionSpec.scala b/src/test/scala/doobie/SelectingDataSectionSpec.scala similarity index 95% rename from src/test/scala/exercises/doobie/SelectingDataSectionSpec.scala rename to src/test/scala/doobie/SelectingDataSectionSpec.scala index c2505f9..45934e3 100644 --- a/src/test/scala/exercises/doobie/SelectingDataSectionSpec.scala +++ b/src/test/scala/doobie/SelectingDataSectionSpec.scala @@ -1,6 +1,5 @@ -package exercises.doobie +package doobie -import doobie._ import org.scalacheck.Shapeless._ import org.scalaexercises.Test import org.scalatest.Spec