Skip to content

Instantly share code, notes, and snippets.

@kkismd
Created June 29, 2015 06:02
Show Gist options
  • Save kkismd/3fff52baa5f1ad564c23 to your computer and use it in GitHub Desktop.
Save kkismd/3fff52baa5f1ad564c23 to your computer and use it in GitHub Desktop.
Skinny ORMのモデルサンプル
package models
import scalikejdbc._
import skinny.orm.{SkinnyCRUDMapper, SkinnyRecord}
case class Example( id: Long, name: Option[String] = None ) extends SkinnyRecord[Example] {
def skinnyCRUDMapper = Example
}
object Example extends SkinnyCRUDMapper[Example] {
override val tableName = "examples"
override lazy val defaultAlias = createAlias("e")
def extract(rs: WrappedResultSet, rn: ResultName[Example]): Example = autoConstruct(rs, rn)
// SQL文の書き方メモ
def demo(): Unit = {
implicit val s = AutoSession
val e = defaultAlias
val a = withSQL { select
.from(Example as e)
.where.eq(e.id, 1)
.orderBy(e.id).asc
}.map(Example(_)).list().apply()
val b = sql"""SELECT ${e.result.*} FROM ${Example as e} WHERE ${e.id} = ${1} ORDER BY ${e.id}
""".map(Example(_)).list().apply()
println(a)
println(b)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment