Last active
August 29, 2015 14:22
-
-
Save kkismd/3340a550a73f5729043f to your computer and use it in GitHub Desktop.
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
CREATE TABLE examples ( | |
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT, | |
name VARCHAR(100) | |
); |
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) | |
} |
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
scala> implicit val s = scalikejdbc.AutoSession [117/229014] | |
s: scalikejdbc.AutoSession.type = AutoSession | |
scala> import scalikejdbc._ | |
import scalikejdbc._ | |
scala> import models.Example | |
import models.Example | |
scala> val e = Example.defaultAlias | |
e: skinny.orm.Alias[models.Example] = QuerySQLSyntaxProvider(models.Example$@6620f9d6,e) | |
scala> withSQL{ select.from(Example as e) }.map(Example(_)).list().apply() | |
res8: List[models.Example] = List(Example(1,Some(foo)), Example(2,Some(bar)), Example(3,Some(baz))) | |
scala> sql"select * from examples".map(Example(_)).list().apply() | |
scalikejdbc.ResultSetExtractorException: Failed to retrieve value because Column 'i_on_e' not found.. If you're using SQLInterpolation, you may mistake u.id for u.resultName.id. | |
at scalikejdbc.WrappedResultSet.wrapIfError(WrappedResultSet.scala:27) | |
at scalikejdbc.WrappedResultSet.get(WrappedResultSet.scala:459) | |
at models.Example$.extract(Example.scala:14) | |
: | |
: | |
scala> sql"select ${e.result.*} from ${Example as e}".map(Example(_)).list().apply() | |
res22: List[models.Example] = List(Example(1,Some(foo)), Example(2,Some(bar)), Example(3,Some(baz))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment