首页 > 代码库 > scalikejdbc 学习笔记(4)
scalikejdbc 学习笔记(4)
Batch 操作
import scalikejdbc._ import scalikejdbc.config._ object BatchOperation { def main(args: Array[String]): Unit = { DBsWithEnv("dev").setupAll() case class User(id: Int, name: String, age: Int) val ls = List[User]( User(5, "aa", 2), User(6, "bb", 8), User(7, "cc", 9)) val lsi = List[User]( User(5, "aau", 2), User(6, "bbu", 8), User(7, "ccu", 9)) val batchInsertParams = for (el <- ls) yield (List(el.id, el.name, el.age)) val batchUpdateParams = for (el <- lsi) yield (List(el.name, el.id)) DB localTx { implicit session => sql"insert into user (id, name, age) values (?, ?, ?)".batch(batchInsertParams: _*).apply() } DB localTx { implicit session => sql"update user set name = ? where id = ?".batch(batchUpdateParams: _*).apply() } DBsWithEnv("dev").closeAll() } }
scalikejdbc 学习笔记(4)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。