使用Slick 3.1,如何將多個查詢合併到同一類型的單個查詢中?這是不是聯接或聯合,但組合查詢「段」來創建單個查詢請求。這些「細分」可以是任何單獨有效的查詢。將光滑查詢合併到單個查詢中
val query = TableQuery[SomeThingValid]
// build up pieces of the query in various parts of the application logic
val q1 = query.filter(_.value > 10)
val q2 = query.filter(_.value < 40)
val q3 = query.sortBy(_.date.desc)
val q4 = query.take(5)
// how to combine these into a single query ?
val finalQ = ??? q1 q2 q3 q4 ???
// in order to run in a single request
val result = DB.connection.run(finalQ.result)
編輯: 預期的SQL應該是這樣的:
SELECT * FROM "SomeThingValid" WHERE "SomeThingValid"."value" > 10 AND "SomeThingValid"."valid" < 40 ORDER BY "MemberFeedItem"."date" DESC LIMIT 5
我不完全確定你期望的結果。我想我必須問:你如何在普通的SQL中做到這一點? –
@PatrykĆwiek更新與預期的例子sql – IUnknown