Skip to content

Commit

Permalink
scalafmt
Browse files Browse the repository at this point in the history
  • Loading branch information
nafg committed Sep 29, 2024
1 parent 02cb002 commit f1b3460
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 28 deletions.
4 changes: 4 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version = 3.8.1

runner.dialect = scala3
align.preset = most
47 changes: 26 additions & 21 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import _root_.io.github.nafg.mergify.dsl.*


name := "slick-codegen-example"


inThisBuild(List(
scalaVersion := "2.13.15",
githubWorkflowPublishTargetBranches := Seq(),
githubWorkflowBuild += WorkflowStep.Sbt(List("run")),
githubWorkflowJavaVersions := Seq(JavaSpec.temurin("11"))
))
inThisBuild(
List(
scalaVersion := "2.13.15",
githubWorkflowPublishTargetBranches := Seq(),
githubWorkflowBuild += WorkflowStep.Sbt(List("run")),
githubWorkflowJavaVersions := Seq(JavaSpec.temurin("11"))
)
)

mergifyExtraConditions := Seq(
(Attr.Author :== "scala-steward") ||
Expand All @@ -22,30 +22,35 @@ scalacOptions += "-deprecation"
val slickVersion = "3.5.1"

libraryDependencies ++= Seq(
"com.typesafe.slick" %% "slick" % slickVersion,
"com.typesafe.slick" %% "slick" % slickVersion,
"com.typesafe.slick" %% "slick-codegen" % slickVersion,
"org.slf4j" % "slf4j-nop" % "2.0.16",
"com.h2database" % "h2" % "2.3.232"
"org.slf4j" % "slf4j-nop" % "2.0.16",
"com.h2database" % "h2" % "2.3.232"
)

(Compile / sourceGenerators) += slick.taskValue // Automatic code generation on build

lazy val slick = taskKey[Seq[File]]("Generate Tables.scala")
slick := {
val dir = (Compile / sourceManaged).value
val dir = (Compile / sourceManaged).value
val outputDir = dir / "slick"
val url = "jdbc:h2:mem:test;INIT=runscript from 'src/main/sql/create.sql'" // connection info
val jdbcDriver = "org.h2.Driver"
val url =
"jdbc:h2:mem:test;INIT=runscript from 'src/main/sql/create.sql'" // connection info
val jdbcDriver = "org.h2.Driver"
val slickDriver = "slick.jdbc.H2Profile"
val pkg = "demo"
val pkg = "demo"

val cp = (Compile / dependencyClasspath).value
val s = streams.value

runner.value.run("slick.codegen.SourceCodeGenerator",
cp.files,
Array(slickDriver, jdbcDriver, url, outputDir.getPath, pkg),
s.log).failed foreach (sys error _.getMessage)
val s = streams.value

runner.value
.run(
"slick.codegen.SourceCodeGenerator",
cp.files,
Array(slickDriver, jdbcDriver, url, outputDir.getPath, pkg),
s.log
)
.failed foreach (sys error _.getMessage)

val file = outputDir / pkg / "Tables.scala"

Expand Down
17 changes: 10 additions & 7 deletions src/main/scala/Example.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ object Tables extends demo.Tables {
override val profile = slick.jdbc.H2Profile
}


import scala.concurrent.Await
import scala.concurrent.duration._
import scala.language.postfixOps
Expand All @@ -12,18 +11,22 @@ import Tables._
import Tables.profile.api._
import scala.concurrent.ExecutionContext.Implicits.global


object Example extends App {
// connection info for a pre-populated throw-away, in-memory db for this demo, which is freshly initialized on every
// run
val url = "jdbc:h2:mem:test;INIT=runscript from 'src/main/sql/create.sql'"
val db = Database.forURL(url, driver = "org.h2.Driver")
val db = Database.forURL(url, driver = "org.h2.Driver")

// Using generated code. Our Build.sbt makes sure they are generated before compilation.
val q = Companies.join(Computers).on(_.id === _.manufacturerId)
val q = Companies
.join(Computers)
.on(_.id === _.manufacturerId)
.map { case (co, cp) => (co.name, cp.name) }

Await.result(db.run(q.result).map { result =>
println(result.groupMap(_._1)(_._2).mkString("\n"))
}, 60 seconds)
Await.result(
db.run(q.result).map { result =>
println(result.groupMap(_._1)(_._2).mkString("\n"))
},
60 seconds
)
}

0 comments on commit f1b3460

Please sign in to comment.