I'm trying to write a query template for like so:
val byIdentifier = for {
(identifier, issuer) <- Parameters[(String, String)]
o <- Objects if (o.identifier === identifier) && (o.identifierIssuer === issuer)
} yield o
And then use it like this:
def findByIdentifier(id: String, issuer: String): Option[Object] =
byIdentifier(id, issuer).firstOption
Objects
is a Table with lifted embedding:
case class Object(val identifer: String, val identifierIssuer: String)
object Objects extends Table[Object]("objects") {
def identifier = column[String]("identifier")
def identifierIssuer = column[String]("identifier_issuer")
...
}
The problem I'm experiencing is that findByIdentifier("asdf", "weqr")
produces a query with a where
clause that is just false
:
select ... from "objects" where false
What am I missing in my query template to have proper querying?
Try the following syntax:
val byIdentifier = for {
(identifier, issuer) <- Parameters[(String, String)]
o <- Objects
if o.identifier === identifier
if o.identifierIssuer === issuer
} yield o
I often find that slick can be a bit wonky with its syntax, and the current documentation isn't particularly good.
You could also make your findByIdentifier
do the work:
def findByIdentifier(id: String, issuer: String): Option[Object] = {
Query(Object).where(_.identifier === id).where(_.identifierIssuer === issuer).run.headOption
}
I hope that helps...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With