def createRequest(url: String, verb: String, createdAt: Timestamp) =
newUrlScanRequests += (url, verb, createdAt)
def lookupRequest(url: Rep[String], verb: Rep[String]) =
urlScanRequests filter (r => r.url === url && r.verb === verb)
val lookupRequestWith = Compiled(lookupRequest _)
def lookupOrCreate(url: String, verb: String, createdAt: Timestamp = new Timestamp(new Date().getTime))
(implicit ec: ExecutionContext) =
lookupRequestWith(url, verb).result.headOption.flatMap {
case Some((id, url, verb, createdAt)) =>
DBIO.successful(Request(id, url, verb, createdAt))
case None =>
createRequest(url, verb, createdAt) map (id => Request(id, url, verb, createdAt))
}
--
---
You received this message because you are subscribed to the Google Groups "Slick / ScalaQuery" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalaquery+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scalaquery/c2c9f4fa-51d8-46fd-97bd-bd474f392f5c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
result.headOption further returns a DBIO. result gives you a Seq, headOption gives you an Option, and head gives you a plain row value. You can also call .to[List] (or Set or Stream etc.) to build that collection type. But those all work within DBIO.
--
--
---
You received this message because you are subscribed to a topic in the Google Groups "Slick / ScalaQuery" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/scalaquery/C0Cev0_TN2E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to scalaquery+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scalaquery/CANpg8PAofgHMRXwhKW2jwhM8-SrbqEtPmSQvoncxQ%3DyUi5d3bg%40mail.gmail.com.