Created
March 14, 2012 16:15
-
-
Save elbowich/2037578 to your computer and use it in GitHub Desktop.
basic scalaquery project
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
resolvers += ScalaToolsReleases | |
libraryDependencies ++= Seq( | |
"org.scalaquery" % "scalaquery_2.9.0-1" % "0.9.5" withSources(), | |
"com.h2database" % "h2" % "1.3.158" | |
) |
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
import org.scalaquery.ql.extended.{ExtendedTable => Table} | |
case class Writer(id: Option[Long] = None, firstName: String, lastName: Option[String] = None) | |
object Writers extends Table[Writer]("Writer") { | |
def id = column[Long]("id", O PrimaryKey, O AutoInc) | |
def firstName = column[String]("firstName") | |
def lastName = column[Option[String]]("lastName") | |
def * = id.? ~ firstName ~ lastName <>(Writer.apply _, Writer.unapply _) | |
} | |
object Main extends App { | |
import org.scalaquery.session.{Database, Session} | |
import org.scalaquery.ql.Query | |
import org.scalaquery.ql.extended.H2Driver.Implicit._ | |
val db = Database.forURL("jdbc:h2:mem:db", driver = "org.h2.Driver") | |
db.withSession { | |
implicit s: Session => Writers.ddl.create | |
List( | |
Writer(id = Some(1), firstName = "Peter", lastName = Some("Kropotkin")), | |
Writer(firstName = "Leo", lastName = Some("Tolstoy")), | |
Writer(firstName = "Fyodor") | |
).foreach(Writers.insert) | |
assert(Query(Writers).list().size == 3) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment