Skip to content

Instantly share code, notes, and snippets.

@letusfly85
Last active August 29, 2015 14:00
Show Gist options
  • Save letusfly85/32f0ea662a9daa42d71f to your computer and use it in GitHub Desktop.
Save letusfly85/32f0ea662a9daa42d71f to your computer and use it in GitHub Desktop.
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)
}
}
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,)"
)
@letusfly85
Copy link
Author

check scaffold

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment