Last active
August 29, 2015 14:00
-
-
Save letusfly85/32f0ea662a9daa42d71f to your computer and use it in GitHub Desktop.
This file contains 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 sample | |
import scalikejdbc._ | |
import SQLInterpolation._ | |
/** | |
* http://scalikejdbc.org/ | |
* | |
*/ | |
object Main { | |
def main(args: Array[String]) { | |
Class.forName("com.mysql.jdbc.Driver") | |
ConnectionPool.singleton("jdbc:mysql://localhost/host", "user", "pass") | |
implicit val session = AutoSession | |
println(session) | |
sql""" | |
create table members ( | |
id serial not null primary key, | |
name varchar(64), | |
created_at timestamp not null | |
) | |
""".execute.apply() | |
// insert initial data | |
Seq("Alice", "Bob", "Chris") foreach { name => | |
sql"insert into members (name, created_at) values (${name}, current_timestamp)".update.apply() | |
} | |
val entities: List[Map[String, Any]] = sql"select * from members".map(_.toMap).list.apply() | |
entities.foreach(println) | |
} | |
} |
This file contains 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
name := "useScalikeJDBC" | |
version := "1.0" | |
scalaVersion := "2.10.2" | |
resolvers += "scct-github-repository" at "http://mtkopone.github.com/scct/maven-repo" | |
resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/" | |
libraryDependencies ++= Seq( | |
"org.scalikejdbc" %% "scalikejdbc" % "1.7.5", | |
"org.scalikejdbc" %% "scalikejdbc-interpolation" % "1.7.5", | |
"mysql" % "mysql-connector-java" % "5.1.30", | |
"ch.qos.logback" % "logback-classic" % "[1.1,)" | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
check scaffold