Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Scala to 2.13 with -Xsource:3 and add scalafmt #77

Merged
merged 1 commit into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12.19]
scala: [2.13.15]
java: [temurin@11]
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pull_request_rules:
- author=scala-steward
- author=slick-scala-steward[bot]
- author=renovate[bot]
- check-success=Build and Test (ubuntu-latest, 2.12.19, temurin@11)
- check-success=Build and Test (ubuntu-latest, 2.13.15, temurin@11)
actions:
queue:
name: default
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.3

runner.dialect = Scala213Source3
align.preset = most
18 changes: 12 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import _root_.io.github.nafg.mergify.dsl.*

inThisBuild(
List(
scalaVersion := "2.13.15",
scalacOptions += "-Xsource:3"
)
)

mergifyExtraConditions := Seq(
(Attr.Author :== "scala-steward") ||
(Attr.Author :== "slick-scala-steward[bot]") ||
(Attr.Author :== "renovate[bot]")
)
libraryDependencies ++= List(
"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"
)

scalacOptions += "-deprecation"
Expand All @@ -20,8 +26,8 @@ libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value
Compile / unmanagedClasspath ++= (Compile / unmanagedResources).value
libraryDependencies += "com.typesafe.slick" %% "slick" % "3.5.1"

ThisBuild / githubWorkflowJavaVersions := Seq(JavaSpec.temurin("11"))

ThisBuild / githubWorkflowBuild := Seq(WorkflowStep.Sbt(List("runAll"), name = Some(s"Run all main classes")))

ThisBuild / githubWorkflowJavaVersions := Seq(JavaSpec.temurin("11"))
ThisBuild / githubWorkflowPublishTargetBranches := Seq()
ThisBuild / githubWorkflowBuild := Seq(
WorkflowStep.Sbt(List("runAll"), name = Some(s"Run all main classes"))
)
6 changes: 3 additions & 3 deletions runAll.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
lazy val runAll = taskKey[Unit]("Run all main classes")

def runAllIn(config: Configuration) = Def.task {
val s = streams.value
val cp = (config / fullClasspath).value
val r = (config / run / runner).value
val s = streams.value
val cp = (config / fullClasspath).value
val r = (config / run / runner).value
val classes = (config / discoveredMainClasses).value
classes.foreach { className =>
r.run(className, cp.files, Seq(), s.log).get
Expand Down
15 changes: 0 additions & 15 deletions src/main/scala/Transfer.scala

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import slick.jdbc.H2Profile.api._
package slick.examples.plainsql

import scala.concurrent.ExecutionContext.Implicits.global

trait Interpolation { this: PlainSQL.type =>
import slick.jdbc.H2Profile.api.*

def createCoffees: DBIO[Int] =
sqlu"""create table coffees(
name varchar not null,
sup_id int not null,
price double not null,
sales int not null,
total int not null,
foreign key(sup_id) references suppliers(id))"""
//noinspection MutatorLikeMethodIsParameterless
trait Interpolation { this: PlainSQL.type =>

def createSuppliers: DBIO[Int] =
sqlu"""create table suppliers(
Expand All @@ -22,6 +16,15 @@ trait Interpolation { this: PlainSQL.type =>
state varchar not null,
zip varchar not null)"""

def createCoffees: DBIO[Int] =
sqlu"""create table coffees(
name varchar not null,
sup_id int not null,
price double not null,
sales int not null,
total int not null,
foreign key(sup_id) references suppliers(id))"""

def insertSuppliers: DBIO[Unit] = DBIO.seq(
// Insert some suppliers
sqlu"insert into suppliers values(101, 'Acme, Inc.', '99 Market Street', 'Groundsville', 'CA', '95199')",
Expand Down Expand Up @@ -51,16 +54,20 @@ trait Interpolation { this: PlainSQL.type =>
// Iterate through all coffees and output them
sql"select * from coffees".as[Coffee].map { cs =>
println("Coffees:")
for(c <- cs)
println("* " + c.name + "\t" + c.supID + "\t" + c.price + "\t" + c.sales + "\t" + c.total)
for (c <- cs)
println(
"* " + c.name + "\t" + c.supID + "\t" + c.price + "\t" + c.sales + "\t" + c.total
)
}

def namesByPrice(price: Double): DBIO[Seq[(String, String)]] = sql"""
// noinspection SameParameterValue
private def namesByPrice(price: Double): DBIO[Seq[(String, String)]] = sql"""
select c.name, s.name
from coffees c, suppliers s
where c.price < $price and s.id = c.sup_id""".as[(String, String)]

def supplierById(id: Int): DBIO[Seq[Supplier]] =
// noinspection SameParameterValue
private def supplierById(id: Int): DBIO[Seq[Supplier]] =
sql"select * from suppliers where id = $id".as[Supplier]

def printParameterized: DBIO[Unit] = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import scala.concurrent.{Future, Await}
package slick.examples.plainsql

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration.Duration
import slick.jdbc.H2Profile.api._
import scala.concurrent.{Await, Future}

import slick.jdbc.H2Profile.api.*

/** A simple example that uses plain SQL queries against an in-memory
* H2 database. The example data comes from Oracle's JDBC tutorial at
* http://download.oracle.com/javase/tutorial/jdbc/basics/tables.html. */
/** A simple example that uses plain SQL queries against an in-memory H2
* database. The example data comes from Oracle's JDBC tutorial at
* http://download.oracle.com/javase/tutorial/jdbc/basics/tables.html.
*/
object PlainSQL extends App with Interpolation with Transfer {
val db = Database.forConfig("h2mem1")
try {
val f: Future[_] = {
val f: Future[?] = {

val a: DBIO[Unit] = DBIO.seq(
createSuppliers,
Expand Down
37 changes: 37 additions & 0 deletions src/main/scala/slick/examples/plainsql/Transfer.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package slick.examples.plainsql
import slick.jdbc.GetResult

/** The Data Transfer Objects for the PlainSQL app */
trait Transfer { this: PlainSQL.type =>

// Case classes for our data
case class Supplier(
id: Int,
name: String,
street: String,
city: String,
state: String,
zip: String
)
case class Coffee(
name: String,
supID: Int,
price: Double,
sales: Int,
total: Int
)

// Result set getters
implicit val getSupplierResult: GetResult[Supplier] = GetResult(r =>
Supplier(
r.nextInt(),
r.nextString(),
r.nextString(),
r.nextString(),
r.nextString(),
r.nextString()
)
)
implicit val getCoffeeResult: GetResult[Coffee] =
GetResult(r => Coffee(r.<<, r.<<, r.<<, r.<<, r.<<))
}