0

I'm experimenting with scalikejdbc (trying to move from Slick), and I'm stuck on creating my schema from the entities (read: case classes).

// example Slick equivalent

case class X(id: Int, ...)

class XTable(tag: Tag) extends Table[X] (tag, "x") {
  def id = column[Int]("id")
  ... //more columns

  def * = (id, ...) <> (X.tupled, X.unapply)
}

val xTable = TableQuery[XTable]

db.run(xtable.schema.create) //creates in the DB a table named "x", with "id" and all other columns

It seemed like using SQLSyntaxSupport could be a step in the right direction, with something like

// scalikejdbc

case class X (id: Int, ...)

object X extends SQLSyntaxSupport[X] {
  def apply (x: ResultName[X])(rs: WrappedResultSet): X = new X(id = rs.get(x.id, ...))
}

X.table.??? // what to do now?

but could not figure out the next step.

What I'm looking for is the opposite of the tool described under [Reverse-engineering]: http://scalikejdbc.org/documentation/reverse-engineering.html

Any help/ideas, in particular directions to a relevant part of the documentation, will be appreciated

iDPWF1
  • 451
  • 1
  • 5
  • 10

1 Answers1

0

You can use the the statements method to get the SQL code, like for most other SQL-based Actions. Schema Actions are currently the only Actions that can produce more than one statement.

schema.create.statements.foreach(println)
schema.drop.statements.foreach(println)

http://slick.typesafe.com/doc/3.0.0/schemas.html

Vitalii Kotliarenko
  • 2,947
  • 18
  • 26