首页 > 代码库 > scalikejdbc 学习笔记(5)
scalikejdbc 学习笔记(5)
常用增删改查操作:
import scalikejdbc._ import scalikejdbc.config._ object CommonOperation { def main(args: Array[String]): Unit = { DBsWithEnv("dev").setupAll() case class Emp(id: Int, name: String) DB autoCommit { implicit session => sql"create table emp ( id int(20) not null AUTO_INCREMENT, name varchar(30), primary key (id))".execute.apply() } val id = 1 val name = "sky" val newName = "bill" DB localTx { implicit session => sql"""insert into emp (name) values (${name})""" .update.apply() val idd = sql"insert into emp (name) values (${name})" .updateAndReturnGeneratedKey.apply() println("new insert: " + idd) sql"update emp set name = ${newName} where id = ${id}".update.apply() sql"delete emp where id = ${id}".update.apply() val emps: List[Emp] = sql"select id, name from emp".map( (rs: WrappedResultSet) => Emp( id = rs.int("id"), name = rs.string("name"))).list.apply() for (emp <- emps) { println(emp.id + "," + emp.name) } } DBsWithEnv("dev").closeAll() } }
scalikejdbc 学习笔记(5)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。