-
-
Save bigdragon1977/7795706 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tests01 | |
object lab { | |
object PreparedStatement { | |
case class Param[A](val index : Int, val value : A) | |
case class BoundSql(val sql: String, val params : Seq[Param[_]]) | |
implicit class SqlStringContext(val sc : StringContext) extends AnyVal { | |
def sql(args : Any*) = BoundSql(sc.parts.mkString("?"), | |
((1 to args.length) zip args).map(x => Param(x._1,x._2))) | |
} | |
} | |
import PreparedStatement._ | |
val id = 500 //> id : Int = 500 | |
val name = "%test%" //> name : String = %test% | |
println( | |
sql""" | |
SELECT * | |
FROM mytable | |
WHERE id = $id | |
OR name LIKE $name | |
""" | |
) //> BoundSql( | |
//| SELECT * | |
//| FROM mytable | |
//| WHERE id = ? | |
//| OR name LIKE ? | |
//| ,Vector(Param(1,500), Param(2,%test%))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment