Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from tarao/pluggable-placeholders
Make placeholders pluggable.
- Loading branch information
Showing
7 changed files
with
859 additions
and
57 deletions.
There are no files selected for viewing
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
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
27 changes: 27 additions & 0 deletions
27
src/main/scala/com/github/tarao/slickjdbc/interpolation/Placeholder.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.github.tarao | ||
package slickjdbc | ||
package interpolation | ||
|
||
class Placeholder extends Literal { | ||
import Placeholder.{stripParen, dropLast} | ||
def toSeq: Seq[Placeholder] = Seq(this) | ||
def toTopLevelString: String = dropLast(stripParen(toString)) | ||
override def toString: String = "?" | ||
} | ||
object Placeholder { | ||
private def stripParen(str: String) = str.stripPrefix("(").stripSuffix(")") | ||
private def dropLast(str: String) = str.stripSuffix("?") | ||
|
||
def apply(): Placeholder = new Placeholder | ||
def repeat(n: Int): Seq[Placeholder] = (1 to n).map(_ => apply()) | ||
|
||
class Nested(children: Placeholder*) extends Placeholder { | ||
override def toSeq: Seq[Placeholder] = children | ||
override def toString: String = | ||
s"""(${stripParen(children.map(_.toString).mkString(", "))})""" | ||
} | ||
object Nested { | ||
def apply(children: Placeholder*): Nested = new Nested(children: _*) | ||
def apply(n: Int): Nested = new Nested(Placeholder.repeat(n): _*) | ||
} | ||
} |
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
Oops, something went wrong.