Skip to content

Instantly share code, notes, and snippets.

@pedrofurla
Created December 6, 2012 15:11
Show Gist options
  • Save pedrofurla/4225153 to your computer and use it in GitHub Desktop.
Save pedrofurla/4225153 to your computer and use it in GitHub Desktop.
Alternative to Table.createFinder working!
def equalBy[B: BaseTypeMapper]
(proj:Entities.type => Column[B])(str:B):Query[Entities.type,Entity] = {
Query(Entities) where { x => proj(x) === str}
}
val q = Entities.equalBy({ _.name })("5")
//> q : scala.slick.lifted.Query[test.whereCreator.Entities.type,test.whereCrea
//| tor.Entity] = scala.slick.lifted.WrappingQuery@6401d98a
q.selectStatement
//> res0: String = select x2."id", x2."name" from "entity" x2 where x2."name" = '5'
@szeiger
Copy link

szeiger commented Dec 6, 2012

def testComposition {
import scala.slick.lifted.{CanBeQueryCondition, OptionMapper2}
def equalBy[B, P1, P2, PR](proj: Users.type => Column[P1])(str: P2)
(implicit om: OptionMapper2[B, B, Boolean, P1, P2, PR], cb: CanBeQueryCondition[Column[PR]], t2: ColumnType[P2])
: Query[Users.type, (Int, String, Option[String])] =
Query(Users).filter(x => new ColumnExtensionMethodsB, P1 === ConstColumn(str))
}

@szeiger
Copy link

szeiger commented Dec 6, 2012

Let's try that again:

import scala.slick.lifted.{CanBeQueryCondition, OptionMapper2}
def equalBy[B, P1, P2, PR]
    (proj: Users.type => Column[P1])(str: P2)
    (implicit om: OptionMapper2[B, B, Boolean, P1, P2, PR], cb: CanBeQueryCondition[Column[PR]], t2: ColumnType[P2])
    : Query[Users.type, (Int, String, Option[String])] =
  Query(Users).filter(x => new ColumnExtensionMethods[B, P1](proj(x)) === ConstColumn(str))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment