问题描述:

I want to delete rows from a few tables. My exact intention is depicted in the pseudo SQL statements below,

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 table has 2 columns users_oid and login_infos_oid and joins users and login_infos tables . How do I this nicely in Slick 3.x within a transaction? Thanks.

网友答案:

I do not think this is a good solution but for the time being this is what it is,

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)
相关阅读:
Top