Slick是TypeSafe推出的Scala数据库访问库。开发者可以使用Scala语言风格来编写数据查询,而不是用SQL,示例代码:
objectCoffeesextendsTable[(String,Int,Double)]("COFFEES"){defname=column[String]("COF_NAME",O.PrimaryKey)defsupID=column[Int]("SUP_ID")defprice=column[Double]("PRICE")def*=name~supID~price}Coffees.insertAll(("Colombian",101,7.99),("Colombian_Decaf",101,8.99),("French_Roast_Decaf",49,9.99))valq=for{c<-Coffeesifc.supID===101//^comparingRep[Int]toRep[Int]!}yield(c.name,c.price)println(q.selectStatement)q.foreach{case(n,p)=>println(n+":"+p)}点击空白处退出提示
评论