Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
slick-for-update-sample/src/main/scala/Driver.scala
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
52 lines (41 sloc)
1.46 KB
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
package myapp | |
import slick.driver.PostgresDriver | |
trait MyPostgresDriver extends PostgresDriver | |
with PgForUpdateSupport | |
{ | |
override val simple = new SimpleQLPlus {} | |
trait SimpleQLPlus extends SimpleQL | |
with ForUpdateTableImplicits | |
} | |
object MyPostgresDriver extends MyPostgresDriver | |
trait PgForUpdateSupport extends PostgresDriver { driver => | |
import scala.slick.ast.{Comprehension, Node, Symbol, TableNode} | |
import scala.slick.compiler.CompilerState | |
trait ForUpdateTable | |
trait ForUpdateTableImplicits { | |
type ForUpdateTable = driver.ForUpdateTable | |
} | |
class QueryBuilder(tree: Node, state: CompilerState) extends super.QueryBuilder(tree, state) { | |
import scala.slick.util.MacroSupport.macroSupportInterpolation | |
override protected def buildComprehension(c: Comprehension): Unit = { | |
super.buildComprehension(c) | |
buildForUpdateClause(c.from) | |
} | |
protected def buildForUpdateClause(from: Seq[(Symbol, Node)]) = building(FromPart) { | |
val forUpdateFrom = from.filter { case (_, n) => | |
n match { | |
case TableNode(_, _, _, driverTable, _) => | |
driverTable.isInstanceOf[ForUpdateTable] | |
case _ => false | |
} | |
} | |
if(!forUpdateFrom.isEmpty) { | |
b" for update of " | |
b.sep(forUpdateFrom , ", ") { case (sym, n) => | |
b += symbolName(sym) | |
} | |
} | |
} | |
} | |
override def createQueryBuilder(n: Node, state: CompilerState): QueryBuilder = new QueryBuilder(n, state) | |
} | |