Permalink
Browse files

backported fix for #105

  • Loading branch information...
szeiger authored and cvogt committed Feb 21, 2013
1 parent 2906a88 commit d79375c26b16ee4ebe3040aa84a406f3a2301ff3
@@ -72,7 +72,7 @@ class DumpContext(val out: PrintWriter) {
case _ =>
out.println(prefix + name + tree)
for((chg, n) <- tree.nodeChildren.zip(tree.nodeChildNames))
dump(Node(chg), prefix + " ", n+": ")
dump(chg, prefix + " ", n+": ")
}
}
}
@@ -195,6 +195,12 @@ final case class Filter(generator: Symbol, from: Node, where: Node) extends Filt
def nodePostGeneratorChildren = Seq(where)
}
object Filter {
def ifRefutable(generator: Symbol, from: Node, where: Node): Node =
if(where match { case LiteralNode(true) => true; case _ => false }) from
else Filter(generator, from, where)
}
/** A .sortBy call of type
* (CollectionType(c, t), _) => CollectionType(c, t). */
final case class SortBy(generator: Symbol, from: Node, by: Seq[(Node, Ordering)]) extends FilteredQuery with SimpleNode with SimpleDefNode {
@@ -176,7 +176,7 @@ class SlickBackend( driver:BasicDriver, mapper:Mapper ) extends QueryableBackend
val new_scope = scope+(arg.symbol -> sq.Ref(sq_symbol))
val rhs = s2sq(body, new_scope)
new Query( term.decoded match {
case "filter" => sq.Filter( sq_symbol, sq_lhs, rhs.node )
case "filter" => sq.Filter.ifRefutable( sq_symbol, sq_lhs, rhs.node )
case "map" => sq.Bind( sq_symbol, sq_lhs, sq.Pure(rhs.node) )
case "flatMap" => sq.Bind( sq_symbol, sq_lhs, rhs.node )
case e => throw new UnsupportedMethodException( scala_lhs.tpe.erasure+"."+term.decoded )
@@ -26,7 +26,7 @@ abstract class AbstractTable[T](val schemaName: Option[String], val tableName: S
val fv = Library.==(Node(targetColumns(aliased.value)), Node(sourceColumns))
val fk = ForeignKey(name, this, q.unpackable.asInstanceOf[ShapedValue[TT, _]],
targetTable, unpackp, sourceColumns, targetColumns, onUpdate, onDelete)
new ForeignKeyQuery[TT, U](Filter(generator, Node(q), fv), q.unpackable, IndexedSeq(fk), q, generator, aliased.value)
new ForeignKeyQuery[TT, U](Filter.ifRefutable(generator, Node(q), fv), q.unpackable, IndexedSeq(fk), q, generator, aliased.value)
}
def primaryKey[T](name: String, sourceColumns: T)(implicit unpack: Shape[T, _, _]): PrimaryKey = PrimaryKey(name, unpack.linearizer(sourceColumns).narrowedLinearizer.getLinearizedNodes)
@@ -75,7 +75,7 @@ class ForeignKeyQuery[E <: TableNode, U](
val conditions =
newFKs.map(fk => Library.==(Node(fk.targetColumns(aliasedValue)), Node(fk.sourceColumns))).
reduceLeft[Node]((a, b) => Library.And(a, b))
val newDelegate = Filter(generator, Node(targetBaseQuery), conditions)
val newDelegate = Filter.ifRefutable(generator, Node(targetBaseQuery), conditions)
new ForeignKeyQuery[E, U](newDelegate, base, newFKs, targetBaseQuery, generator, aliasedValue)
}
}
@@ -35,7 +35,7 @@ abstract class Query[+E, U] extends Rep[Seq[U]] with CollectionLinearizer[Seq, U
val generator = new AnonSymbol
val aliased = unpackable.encodeRef(generator)
val fv = f(aliased.value)
new WrappingQuery[E, U](Filter(generator, Node(this), Node(wt(fv))), unpackable)
new WrappingQuery[E, U](Filter.ifRefutable(generator, Node(this), Node(wt(fv))), unpackable)
}
def withFilter[T : CanBeQueryCondition](f: E => T) = filter(f)

0 comments on commit d79375c

Please sign in to comment.