Hi,
I have already asked this question in
Stack Overflow. I am asking since I didn't get any response there.
In slick-2, I could pass the same session between multiple methods as implicit arguments and handle the multiple db calls in a single transaction. However, with slick-3,
withTransaction is deprecated and recommend to use
transactionally. I want to abstract the Create/Delete/Update operations to common methods, which can be used by others. However, to use transactionally, we need to have the Query. But if the quer object is used, the extra operations after the create/delete/update needs to be handled by each of the developers when using transactions. Is there a way similar to slick-2, where you can share the same database session to handle the transactions?
def insertWithTransaction(row: TTable#TableElementType)(implicit session: Session) = {
val entity = (query returning query.map(obj => obj) += row).asInstanceOf[TEntity]
// do some operations after insert
// insert record to audit table
//eg: invoke another method for sending the notification
entity
}
override def insert(row: TTable#TableElementType) = {
db.withSession {
implicit session => {
insertWithTransaction(row)
}
}
}