我想从几个表中删除行。我的确切意图在下面的伪SQL语句中描述,
delete from users where oid={user_oid};
login_infos_oid = select login_infos_oid from users_login_infos where users_oid={user_oid};
delete from users_login_infos where users_oid={user_oid};
delete from password_infos where login_infos_oid={login_infos_oid};
delete from login_infos where oid={login_infos_oid};
users_login_infos
表有2列users_oid
和login_infos_oid
,并且加入users
和login_infos
表。在交易中,如何在Slick 3.x中很好地解决这个问题?感谢。
答案 0 :(得分:2)
我认为这不是一个好的解决方案,但目前就是这样,
val userQuery = slickUsers.filter(_.username === username)
val userLoginInfoQuery = slickUserLoginInfos.filter(_.userOid in userQuery.map(_.oid))
val loginInfoQuery = slickLoginInfos.filter(_.oid in userLoginInfoQuery.map(_.loginInfoOid))
val passwordInfoQuery = slickPasswordInfos.filter(_.loginInfoOID in userLoginInfoQuery.map(_.loginInfoOid))
db.run((loginInfoQuery.delete andThen
passwordInfoQuery.delete andThen
userLoginInfoQuery.delete andThen
userQuery.delete).transactionally)