Scala Slick 2.0 updateAll等同于insertALL吗? [英] Scala slick 2.0 updateAll equivalent to insertALL?
问题描述
寻找一种使用滑行进行批处理更新的方法.是否有等效的updateAll插入insertALL?到目前为止,Goole的研究使我失败了.
Looking for a way to do a batch update using slick. Is there an equivalent updateAll to insertALL? Goole research has failed me thus far.
我列出了状态各异的案例类.每个值都有不同的数值,因此我无法运行典型的更新查询.同时,我想保存多个更新请求,因为可能要同时更新成千上万条记录.
I have a list of case classes that have varying status. Each one having a different numeric value so I cannot run the typical update query. At the same time, I want to save the multiple update requests as there could be thousands of records I want to update at the same time.
推荐答案
很抱歉回答我自己的问题,但是我最终要做的只是拖放到JDBC并进行batchUpdate.
Sorry to answer my own question, but what i ended up doing is just dropping down to JDBC and doing batchUpdate.
private def batchUpdateQuery = "update table set value = ? where id = ?"
/**
* Dropping to jdbc b/c slick doesnt support this batched update
*/
def batchUpate(batch:List[MyCaseClass])(implicit subject:Subject, session:Session) = {
val pstmt = session.conn.prepareStatement(batchUpdateQuery)
batch map { myCaseClass =>
pstmt.setString(1, myCaseClass.value)
pstmt.setString(2, myCaseClass.id)
pstmt.addBatch()
}
session.withTransaction {
pstmt.executeBatch()
}
}
这篇关于Scala Slick 2.0 updateAll等同于insertALL吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!