Created
January 26, 2019 08:30
-
-
Save stk132/c5acd0f8ba85ec7e631250dae05d53f8 to your computer and use it in GitHub Desktop.
scalikejdbc back-quoted syntax
This file contains 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
import scalikejdbc._ | |
object MySQLSyntaxSupport { | |
implicit class RichInsertSQLBuilder(val self: InsertSQLBuilder) extends AnyVal { | |
def quotedNamedValues(columnsAndValues: (SQLSyntax, ParameterBinder)*): InsertSQLBuilder = { | |
val (cs, vs) = columnsAndValues.unzip | |
val quotedCs = cs.map {column => sqls"`$column`"} | |
val quotedColumnsAndValues = quotedCs zip vs | |
self.namedValues(quotedColumnsAndValues: _*) | |
} | |
} | |
implicit class RichUpdateSQLBuilder(val self: UpdateSQLBuilder) extends AnyVal { | |
def quotedSet(tuples: (SQLSyntax, ParameterBinder)*): UpdateSQLBuilder = { | |
val (cs, vs) = tuples.unzip | |
val quotedCs = cs.map {column => sqls"`$column`"} | |
val quotedTuples = quotedCs zip vs | |
self.set(sqls.csv(quotedTuples.map(each => sqls"${each._1} = ${each._2}"): _*)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment