Now, I'm writing sample for learning scala slick. I'm using some github projs and stackoverflow (Q&A)s. Below my sample code:
import scala.slick.driver.PostgresDriver.simple._
import Database.threadLocalSession
object TestApp extends App{
case class MyTable(id: Option[Int], foo: String, bar: String)
object MyTables extends Table[MyTable]("mytable") {
def id = column[Int]("id", O.PrimaryKey, O.AutoInc)
def foo = column[String]("foo", O.NotNull)
def bar = column[String]("bar", O.NotNull)
def * = id.? ~ foo ~ bar <> (MyTable, MyTable.unapply _)
def forInsert = foo ~ bar <>
({ (f, l) => MyTable (None, f, l) }, { ep:MyTable => Some((ep.foo, ep.bar)) })
val findByID = createFinderBy(_.id)
}
implicit val session = Database.forURL("jdbc:postgresql://localhost:5432/myserver",
driver="org.postgresql.Driver",
user="myadmin",
password="myadmin")
session withTransaction {
MyTables.ddl.create
MyTables.foo ~ MyTables.bar).insert("Homer", "Simpson")
MyTables.forInsert.insertAll(
MyTable(None, "Marge", "Bouvier"),
MyTable(None, "Carl", "Carlson"),
MyTable(None, "Lenny", "Leonard")
)
}
}
EXCEPTION:
Create table in postgresql
CREATE TABLE mytable
(
id serial primary key,
foo VARCHAR(40) not null,
bar VARCHAR(40) not null,
);
I'm using this tools and libraries:
- Scala IDE - 2.10
- Java version - 1.7.0_11
- slick_2.10.0-M4-0.10.0-M2.jar
- postgresql-9.2-1003-jdbc4.jar
- Database - PostgreSQL 8.3
What's Wrong Here? Thanks in advance.