This is one of my early attempts at implementing a Scala Cake Pattern:
trait dbConfig {
val m: Model = ???
}
trait testDB extends dbConfig {
override val m = new Model(Database.forURL("jdbc:h2:mem:testdb", driver = "org.h2.Driver"))
m.cleanDB
}
trait productionDB extends dbConfig {
override val m = new Model(Database.forURL("jdbc:postgresql:silly:productionDB", driver = "org.postgresql.Driver"))
}
trait SillySystem extends HttpService with dbConfig {
....
// System logic
....
}
This will allow me to use my service like this while testing:
class TestService extends SillySystem with testDB {
.....
}
And like this for production:
class ProductionService extends SillySystem with productionDB {
.....
}
This works, but am I doing it correctly?