[英]Scala Slick MySQL - performing advanced SQL stuff
I have 3 tables in my MySQL db: applications, users and application_images. 我的MySQL数据库中有3个表:应用程序,用户和application_images。 I need to write a query that will generate the next SQL:
我需要编写一个查询,该查询将生成下一个SQL:
SELECT * FROM applications
JOIN users ON applications.user_id=users.id
LEFT JOIN applications_images ON applications_images.app_id=applications.id
WHERE applications.id=?
How can this be achieved with the slick syntax? 如何使用精巧的语法来实现?
And on the same subject: How can I write plain SQL queries with slick (on MySQL DB)? 并在同一主题上:如何使用slick(在MySQL DB上)编写普通的SQL查询?
When using leftJoin
, you use the ?
使用
leftJoin
,使用?
method to project the table to an Option
. 将表投影到
Option
。 Yours might look something like: 您的外观可能类似于:
applications join users on (_.user_id === _.id) map {
case (app, user) => (app, user)
} leftJoin application_images on (_._1.id === _.app_id) map {
case ((app, user), image) => (app, user, image.?)
} filter(_._1.id === {id})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.