Permalink
Browse files

Add strip margin functionality to SQL-interpolated strings

  • Loading branch information...
mwegrz committed Oct 10, 2015
1 parent 3b3bd36 commit 9e88a9baeb960c2e0a02b9fec665baaed9f66f60
@@ -0,0 +1,32 @@
package slick.test.jdbc
import org.junit.Test
import slick.jdbc.JdbcProfile
import org.junit.Assert._
class SqlActionBuilderTest {
@Test
def testStripMargin: Unit = {
val driver = new JdbcProfile {}
import driver.api.actionBasedSQLInterpolation
val id = 0
val s1 = sql"select * from SUPPLIERS where SUP_ID = ${id}"
val s2 = sql"""select *
|from SUPPLIERS
|where SUP_ID = ${id}""".stripMargin
val s3 = sql"""select *
!from SUPPLIERS
!where SUP_ID = ${id}""".stripMargin('!')
val s4 = sql"""select *
#from SUPPLIERS
#where SUP_ID = ${id}""".stripMargin('#')
def dropNewLineChars(queryParts: Seq[Any]): Seq[Any] = queryParts.map(_.asInstanceOf[String].replace('\n', ' '))
assertEquals(s1.queryParts, dropNewLineChars(s2.queryParts))
assertEquals(s1.queryParts, dropNewLineChars(s3.queryParts))
assertEquals(s1.queryParts, dropNewLineChars(s4.queryParts))
}
}
@@ -106,4 +106,7 @@ case class SQLActionBuilder(queryParts: Seq[Any], unitPConv: SetParameter[Unit])
}
}
def asUpdate = as[Int](GetResult.GetUpdateValue).head
def stripMargin(marginChar: Char): SQLActionBuilder =
copy(queryParts.map(_.asInstanceOf[String].stripMargin(marginChar)))
def stripMargin: SQLActionBuilder = copy(queryParts.map(_.asInstanceOf[String].stripMargin))
}

0 comments on commit 9e88a9b

Please sign in to comment.