Created
June 29, 2015 06:02
-
-
Save kkismd/3fff52baa5f1ad564c23 to your computer and use it in GitHub Desktop.
Skinny ORMのモデルサンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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