@@ -11,9 +11,7 @@ import scalaz._, Scalaz._
1111
1212object DoobieUtils {
1313
14- // Transactor for single-use in-memory databases pre-populated with test data.
15- val xa = new Transactor [Task ] {
16-
14+ class CustomTransactor [B ](implicit beforeActions : ConnectionIO [B ]) extends Transactor [Task ] {
1715 val driver = " org.h2.Driver"
1816 def url = " jdbc:h2:mem:"
1917 val user = " sa"
@@ -22,6 +20,11 @@ object DoobieUtils {
2220 val connect : Task [Connection ] =
2321 Task .delay(Class .forName(driver)) *> FD .getConnection(url, user, pass).trans[Task ]
2422
23+ override val before = super .before <* beforeActions
24+ }
25+
26+ object CountryTable {
27+
2528 val createCountryTable : ConnectionIO [Int ] =
2629 sql """
2730 CREATE TABLE IF NOT EXISTS country (
@@ -33,11 +36,28 @@ object DoobieUtils {
3336 """ .update.run
3437
3538 def insertCountries (countries : List [Country ]): ConnectionIO [Int ] =
36- Update [Country ](s " insert into country (code, name, population, gnp) values (?,?,?,?) " ).updateMany(countries)
39+ Update [Country ](" insert into country (code, name, population, gnp) values (?,?,?,?)" )
40+ .updateMany(countries)
3741
38- override val before =
39- super .before <* createCountryTable <* insertCountries(countries)
42+ implicit val beforeActions = createCountryTable <* insertCountries(countries)
4043
44+ // Transactor for single-use in-memory databases pre-populated with test data.
45+ val xa = new CustomTransactor
4146 }
4247
48+ object PersonTable {
49+
50+ val createPersonTable : ConnectionIO [Int ] =
51+ sql """
52+ CREATE TABLE IF NOT EXISTS person (
53+ id IDENTITY,
54+ name VARCHAR NOT NULL UNIQUE,
55+ age INT
56+ )
57+ """ .update.run
58+
59+ implicit val beforeActions = createPersonTable
60+
61+ val xa = new CustomTransactor
62+ }
4363}
0 commit comments