Permalink
Browse files

[scala] Move implicit conversions appart (for cleaner imports):

```scala
import acolyte.Acolyte.{ connection, handleStatement/* ... */ } // DSL
import acolyte.Implicits._ // implicit conversions

val conn = connection(handleStatement { _ => list :+ row })
```
  • Loading branch information...
cchantep
cchantep committed Nov 26, 2013
1 parent 18b94e0 commit 334711bd91f361a1ff591609911f87dccd393c28
View
@@ -336,12 +336,13 @@ import java.sql.{ Connection ⇒ SqlConnection, Date, DriverManager }
import acolyte.{ Driver AcolyteDriver, Execution }
import acolyte.RowLists.{ rowList1, rowList3 }
import acolyte.Rows.row3
import Acolyte._ // import DSL
import acolyte.Acolyte // DSL
import acolyte.Implicits._
// ...
// Prepare handler
val handler: CompositeHandler = handleStatement.
val handler: CompositeHandler = Acolyte.handleStatement.
withQueryDetection(
"^SELECT ", // regex test from beginning
"EXEC that_proc"). // second detection regex
@@ -646,7 +647,8 @@ object Zoo {
Then following specification can be written, checking that query result is properly selected and mapped:
```scala
import acolyte.Acolyte._
import acolyte.Implicits._
import acolyte.Acolyte.{ connection, handleQuery } // DSL
import acolyte.RowLists.rowList5
import acolyte.Rows.row5
import Zoo._
@@ -17,7 +17,8 @@ import acolyte.RowList.Column
* Acolyte DSL.
*
* {{{
* import acolyte.Acolyte._
* import acolyte.Acolyte.{ connection, handleStatement }
* import acolyte.Implicits._
*
* connection {
* handleStatement.withQueryDetection("…").
@@ -26,7 +27,7 @@ import acolyte.RowList.Column
* }
* }}}
*/
object Acolyte extends ScalaRowLists with ScalaRows with CompositeHandlerImplicits {
object Acolyte {
/**
* Creates a connection, whose statement will be passed to given handler.
@@ -48,7 +49,7 @@ object Acolyte extends ScalaRowLists with ScalaRows with CompositeHandlerImplici
* Creates an empty handler.
*
* {{{
* import acolyte.Acolyte._
* import acolyte.Acolyte.{ connection, handleStatement }
*
* connection { handleStatement }
* }}}
@@ -60,14 +61,26 @@ object Acolyte extends ScalaRowLists with ScalaRows with CompositeHandlerImplici
* (like `handleStatement.withQueryDetection(".*").withQueryHandler(h)`).
*
* {{{
* import acolyte.Acolyte._
* import acolyte.Acolyte.{ connection, handleQuery }
*
* connection { handleQuery { _ ⇒ res }
* }}}
*/
def handleQuery(h: QueryExecution QueryResult): ScalaCompositeHandler =
handleStatement withQueryDetection ".*" withQueryHandler h
}
/**
* Acolyte implicit conversions for Scala use.
*
* {{{
* import acolyte.Implicits._
* }}}
*/
object Implicits
extends ScalaRowLists with ScalaRows with CompositeHandlerImplicits {
/**
* Pimps result row.
*
@@ -90,7 +103,7 @@ object Acolyte extends ScalaRowLists with ScalaRows with CompositeHandlerImplici
}
trait Execution
sealed trait Execution
case class QueryExecution(
sql: String,
@@ -1,6 +1,6 @@
package acolyte
import Acolyte._
import Acolyte.handleStatement
object CompositeHandlerSpec extends org.specs2.mutable.Specification {
"Composite statement handler (scala)" title
@@ -1,6 +1,6 @@
package acolyte
import Acolyte._
import acolyte.Implicits._
object RowSpec extends org.specs2.mutable.Specification {
"Row" title
@@ -5,7 +5,8 @@ import java.sql.{ Connection ⇒ SqlConnection, Date, DriverManager }
import acolyte.{ Driver AcolyteDriver }
import acolyte.RowLists.{ rowList1, rowList3, stringList }
import acolyte.Rows.{ row1, row3 }
import Acolyte._ // import DSL
import acolyte.Acolyte.{ connection, handleQuery, handleStatement } // DSL
import acolyte.Implicits._
/**
* Use cases for testing.

0 comments on commit 334711b

Please sign in to comment.