Skip to content

Commit

Permalink
Fixes conflict between different doobie versions
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscodr committed Jul 14, 2016
1 parent f82ee92 commit bd68538
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 34 deletions.
7 changes: 4 additions & 3 deletions build.sbt
Expand Up @@ -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"),
Expand All @@ -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")
)
)
Expand Down
14 changes: 3 additions & 11 deletions 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
Expand Down Expand Up @@ -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.
*/
Expand Down
14 changes: 10 additions & 4 deletions src/main/scala/doobie/DoobieUtils.scala
Expand Up @@ -2,7 +2,7 @@ package doobie

import java.util.UUID

import doobie.Model.Country
import doobie.Model._
import doobie.imports._

import scalaz.concurrent.Task
Expand All @@ -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),
Expand All @@ -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
}
12 changes: 6 additions & 6 deletions src/main/scala/doobie/Model.scala
Expand Up @@ -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))
)
}
8 changes: 0 additions & 8 deletions 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}
Expand Down Expand Up @@ -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 ==
*
Expand Down
@@ -1,6 +1,5 @@
package exercises.doobie
package doobie

import doobie._
import org.scalacheck.Shapeless._
import org.scalaexercises.Test
import org.scalatest.Spec
Expand Down

0 comments on commit bd68538

Please sign in to comment.