Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ol> <li><p>To extend the Config <em>trait</em> I do not think the cake pattern is required. You should be able to create your Config object like this:</p> <pre><code>import scala.slick.driver.ExtendedDriver object MyExtendedConfig extends play.api.db.slick.Config { override def driverByName: String =&gt; Option[ExtendedDriver] = {name: String =&gt; super.driverByName(name) orElse Map("oracledriverstring" -&gt; OracleDriver).get(name) } lazy val app = play.api.Play.current lazy val driver: ExtendedDriver = driver()(app) } </code></pre> <p>To be able to use it you only need to do: <code>import MyExtendedConfig.driver._</code> instead of <code>import play.slick.db.api.Config.driver._</code>. BTW, I see that the type of the driverByName could have been a Map instead of a Function making it easier to extend. This shouldn't break though, but it would be easier to do it.</p></li> <li><p>I think Jonas Bonér's old blog is a great place to read what the cake pattern is (<a href="http://jonasboner.com/2008/10/06/real-world-scala-dependency-injection-di/" rel="nofollow">http://jonasboner.com/2008/10/06/real-world-scala-dependency-injection-di/</a>). My naive understanding of it is that you have a cake pattern when you have layers that uses the <code>self</code> types:</p> <pre><code>trait FooComponent{ driver: ExtendedDriver =&gt; import driver.simple._ class Foo extends Table[Int]("") { //... } } </code></pre> <p>There are 2 use cases for the cake pattern in slick/play-slick: 1) if you have tables that references other tables (as in the computer database sample) 2) to have control over exactly which database is used at which time or if you use many many different types. By using the Config you do not really need the cake pattern as long as you only have 2 different DBs (one for prod and one for test), which is the point of the Config.</p></li> </ol> <p>Hope this answers your questions and good luck on reading Programming in Scala (loved that book :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload