Advertisement
Guest User

Untitled

a guest
May 26th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. lazy val slickGenerate = taskKey[Seq[File]]("slick code generation from an existing database")
  2.  
  3. slickGenerate := {
  4. import java.io.File
  5. val dbName = ""
  6. val userName = ""
  7. val password = ""
  8. val url = s"jdbc:mysql://localhost:3306/$dbName" // adapt as necessary to your system
  9. val jdbcDriver = "com.mysql.jdbc.Driver" // replace if not MySQL
  10. val slickDriver = "slick.driver.MySQLDriver" // replace if not MySQL
  11. val resultRelativeDir = "model" // directory to create output scala slick definitions at
  12. val targetPackageName = "com.cmp.model" // package name to give it
  13. val resultFilePath = s"$resultRelativeDir/$targetPackageName/Tables.scala" // override the name if you like
  14. val backupFilePath = s"$resultRelativeDir/$targetPackageName/Tables.scala.auto-backup" // override the name if you like
  15. val format = scala.Console.BLUE + scala.Console.BOLD
  16. println(format + s"Backing up existing slick mappings source to: file://${baseDirectory.value}/$backupFilePath")
  17. println(format + s"About to auto-generate slick mappings source from database schema at $url...")
  18. sbt.IO.copyFile(new File(resultFilePath), new File(backupFilePath))
  19. (runner in Compile).value.run("slick.codegen.SourceCodeGenerator", (dependencyClasspath in Compile).value.files, Array(slickDriver, jdbcDriver, url, resultRelativeDir, targetPackageName, userName, password), streams.value.log)
  20. println(format + s"Result: file://${baseDirectory.value}/$resultFilePath" + scala.Console.RESET)
  21. val diff = (s"diff -u $resultFilePath $backupFilePath" #| "colordiff").!!
  22. println(scala.Console.BLUE + s"Changes compared to previous output file, follow, if any.\n\n $diff")
  23. Seq(file(resultFilePath))
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement