Skip to content

Commit

Permalink
Merge branch 'master' into replace_SheathLeafClauses
Browse files Browse the repository at this point in the history
  • Loading branch information
juliano authored Nov 29, 2024
2 parents ee55e69 + e343ba4 commit ba5920d
Show file tree
Hide file tree
Showing 21 changed files with 144 additions and 67 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
timeout-minutes: 15
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4.0.0
- uses: actions/checkout@v4.2.2
- name: Cache sbt
uses: actions/cache@v4
with:
Expand All @@ -29,7 +29,7 @@ jobs:
key: ${{ runner.os }}-${{matrix.scala}}-${{matrix.module}}-${{ hashFiles('**/build.sbt') }}

- name: Setup Java
uses: actions/setup-java@v4.2.2
uses: actions/setup-java@v4.5.0
with:
distribution: temurin
java-version: '17'
Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:
name: Build ${{matrix.scala_short_dot}} - ${{matrix.module}}

steps:
- uses: actions/checkout@v4.0.0
- uses: actions/checkout@v4.2.2
- name: Cache sbt
uses: actions/cache@v4
with:
Expand All @@ -87,7 +87,7 @@ jobs:
key: ${{ runner.os }}-${{matrix.scala}}-${{matrix.module}}-${{ hashFiles('**/build.sbt') }}

- name: Setup Java
uses: actions/setup-java@v4.2.2
uses: actions/setup-java@v4.5.0
with:
distribution: temurin
java-version: '17'
Expand All @@ -108,9 +108,9 @@ jobs:
CI_RELEASE: publishSigned # By default, sbt-ci-release uses the `+publishSigned` which is publishing for all the Scala versions configured, which is not what we want
CI_SNAPSHOT_RELEASE: publish # By default, sbt-ci-release uses the `+publish` which is publishing for all the Scala versions configured, which is not what we want
steps:
- uses: actions/checkout@v4.0.0
- uses: actions/checkout@v4.2.2
- name: Setup Java
uses: actions/setup-java@v4.2.2
uses: actions/setup-java@v4.5.0
with:
distribution: temurin
java-version: '11'
Expand All @@ -122,5 +122,5 @@ jobs:
env:
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
PGP_SECRET: ${{ secrets.PGP_SECRET }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.GETQUILL_SONATYPE_TOKEN_PASSWORD }}
SONATYPE_USERNAME: ${{ secrets.GETQUILL_SONATYPE_TOKEN_USER }}
2 changes: 1 addition & 1 deletion .github/workflows/scala-steward.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
name: Scala Steward
steps:
- name: Scala Steward
uses: scala-steward-org/scala-steward-action@v2.69.0
uses: scala-steward-org/scala-steward-action@v2.71.0
with:
github-app-id: ${{ secrets.SCALA_STEWARD_GITHUB_APP_ID }}
github-app-installation-id: ${{ secrets.SCALA_STEWARD_GITHUB_APP_INSTALLATION_ID }}
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ jobs:
if: ${{ github.event_name == 'pull_request' }}
steps:
- name: Git Checkout
uses: actions/checkout@v3.3.0
uses: actions/checkout@v4.2.2
with:
fetch-depth: '0'
- name: Setup Scala
uses: actions/setup-java@v3.9.0
uses: actions/setup-java@v4.5.0
with:
distribution: temurin
java-version: 17
Expand All @@ -39,11 +39,11 @@ jobs:
if: ${{ ((github.event_name == 'release') && (github.event.action == 'published')) || (github.event_name == 'workflow_dispatch') }}
steps:
- name: Git Checkout
uses: actions/checkout@v3.3.0
uses: actions/checkout@v4.2.2
with:
fetch-depth: '0'
- name: Setup Scala
uses: actions/setup-java@v3.9.0
uses: actions/setup-java@v4.5.0
with:
distribution: temurin
java-version: 17
Expand All @@ -63,12 +63,12 @@ jobs:
if: ${{ (github.event_name == 'push') || ((github.event_name == 'release') && (github.event.action == 'published')) }}
steps:
- name: Git Checkout
uses: actions/checkout@v3.3.0
uses: actions/checkout@v4.2.2
with:
ref: ${{ github.head_ref }}
fetch-depth: '0'
- name: Setup Scala
uses: actions/setup-java@v3.9.0
uses: actions/setup-java@v4.5.0
with:
distribution: temurin
java-version: 17
Expand All @@ -82,7 +82,7 @@ jobs:
git add README.md
git commit -m "Update README.md" || echo "No changes to commit"
- name: Create Pull Request
uses: peter-evans/create-pull-request@v4.2.3
uses: peter-evans/create-pull-request@v7.0.5
with:
body: |-
Autogenerated changes after running the `sbt docs/generateReadme` command of the [zio-sbt-website](https://zio.dev/zio-sbt) plugin.
Expand Down
16 changes: 8 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ lazy val `quill-core` =
.settings(
libraryDependencies ++= Seq(
"com.typesafe" % "config" % "1.4.3",
"dev.zio" %% "zio-logging" % "2.3.1",
"dev.zio" %% "zio-logging" % "2.4.0",
"dev.zio" %% "zio" % Version.zio,
"dev.zio" %% "zio-streams" % Version.zio,
"com.typesafe.scala-logging" %% "scala-logging" % "3.9.5"
Expand Down Expand Up @@ -510,7 +510,7 @@ lazy val `quill-orientdb` =
.settings(
Test / fork := true,
libraryDependencies ++= Seq(
"com.orientechnologies" % "orientdb-graphdb" % "3.2.33"
"com.orientechnologies" % "orientdb-graphdb" % "3.2.36"
)
)
.dependsOn(
Expand All @@ -531,11 +531,11 @@ lazy val `quill-test-kit` =

lazy val jdbcTestingLibraries = Seq(
libraryDependencies ++= Seq(
"com.zaxxer" % "HikariCP" % "5.1.0" exclude ("org.slf4j", "*"),
"com.mysql" % "mysql-connector-j" % "9.0.0" % Test,
"com.zaxxer" % "HikariCP" % "6.2.1" exclude ("org.slf4j", "*"),
"com.mysql" % "mysql-connector-j" % "9.1.0" % Test,
"com.h2database" % "h2" % "2.3.232" % Test,
"org.postgresql" % "postgresql" % "42.7.4" % Test,
"org.xerial" % "sqlite-jdbc" % "3.46.1.0" % Test,
"org.xerial" % "sqlite-jdbc" % "3.47.1.0" % Test,
"com.microsoft.sqlserver" % "mssql-jdbc" % "7.4.1.jre11" % Test,
"com.oracle.ojdbc" % "ojdbc8" % "19.3.0.0" % Test,
"org.mockito" %% "mockito-scala-scalatest" % "1.17.14" % Test
Expand Down Expand Up @@ -598,14 +598,14 @@ def excludePaths(paths: Seq[String]) = {
}

val scala_v_12 = "2.12.20"
val scala_v_13 = "2.13.14"
val scala_v_30 = "3.3.3"
val scala_v_13 = "2.13.15"
val scala_v_30 = "3.3.4"

val scalaCollectionCompatVersion = "2.12.0"

lazy val loggingSettings = Seq(
libraryDependencies ++= Seq(
"ch.qos.logback" % "logback-classic" % "1.5.8" % Test
"ch.qos.logback" % "logback-classic" % "1.5.12" % Test
)
)

Expand Down
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import sbt.*
import sbt.Keys.*

object Version {
val zio = "2.1.9"
val zio = "2.1.13"
}

sealed trait ExcludeTests
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.10.1
sbt.version=1.10.5
4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ resolvers += "Typesafe repository" at "https://repo.typesafe.com/typesafe/releas
addDependencyTreePlugin

addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.2.0")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.2.2")
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.1.4")
addSbtPlugin("com.etsy" % "sbt-compile-quick-plugin" % "1.4.0")
addSbtPlugin("dev.zio" % "zio-sbt-website" % "0.3.10")
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.6.1")
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.9.0")
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,11 @@ class ActionMacro(val c: MacroContext) extends ContextMacro with ReifyLiftings {
}
}
case other =>
c.fail(s"Batch actions must be static quotations. Found: '$other'")
c.fail(s"""Batch actions must be static quotations. Found: '$other'.
|It's possible this is being caused by type ascription when declaring the implicit
|schema meta, so try removing it if that's the case, e.g.:
`implicit val schema: ctx.SchemaMeta[Row] = schemaMeta[Row]("rows")` ->
`implicit val schema = schemaMeta[Row]("rows")`""")
}

object ExtractLiftings {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,25 @@ trait ContextTranslateProto {
extractor: Extractor[T] = identityExtractor,
prettyPrint: Boolean = false
)(executionInfo: ExecutionInfo, dc: Runner): TranslateResult[String] =
push(prepareParams(statement, prepare)) { params =>
val query =
if (params.nonEmpty) {
params.foldLeft(statement) { case (expanded, param) =>
expanded.replaceFirst("\\?", param)
try {
push(prepareParams(statement, prepare)) { params =>
val query =
if (params.nonEmpty) {
params.foldLeft(statement) { case (expanded, param) =>
expanded.replaceFirst("\\?", param)
}
} else {
statement
}
} else {
statement
}

if (prettyPrint)
idiom.format(query)
else
query
if (prettyPrint)
idiom.format(query)
else
query
}
} catch {
case e: Exception =>
wrap("<!-- Cannot display parameters due to preparation error: " + e.getMessage + " -->\n" + statement)
}

def translateBatchQuery(
Expand Down
22 changes: 19 additions & 3 deletions quill-engine/src/main/scala/io/getquill/AstPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ object AstPrinter {
}
}

class AstPrinter(traceOpinions: Boolean, traceAstSimple: Boolean, traceQuats: QuatTrace) extends pprint.Walker {
class AstPrinter(
traceOpinions: Boolean = false,
traceAstSimple: Boolean = false,
traceQuats: QuatTrace = QuatTrace.None
) extends pprint.Walker {
val defaultWidth: Int = 150
val defaultHeight: Int = Integer.MAX_VALUE
val defaultIndent: Int = 2
Expand Down Expand Up @@ -83,7 +87,8 @@ class AstPrinter(traceOpinions: Boolean, traceAstSimple: Boolean, traceQuats: Qu
def apply(list: Any*): treemake = Content(list.toList.map(Elem.apply))
}

override def treeify(x: Any, escapeUnicode: Boolean, showFieldNames: Boolean): Tree =
override def treeify(x: Any, escapeUnicode: Boolean, showFieldNames: Boolean): Tree = {
def treeify1(x: Any) = treeify(x, escapeUnicode, showFieldNames)
x match {
case ast: Ast if (traceAstSimple) =>
Tree.Literal("" + ast) // Do not blow up if it is null
Expand Down Expand Up @@ -117,7 +122,16 @@ class AstPrinter(traceOpinions: Boolean, traceAstSimple: Boolean, traceQuats: Qu

case s: ScalarValueLift => Tree.Apply("ScalarValueLift", treemake(s.name, s.source).withQuat(s.bestQuat).make)

case p: Property if (traceOpinions) =>
case i: Infix =>
TreeApplyList(
"Infix",
List(
Tree.KeyValue("parts", ltree(i.parts.map(treeify1(_)))),
Tree.KeyValue("params", ltree(i.params.map(treeify1(_))))
)
)

case p: Property =>
TreeApplyList(
"Property",
l(treeify(p.ast, escapeUnicode, showFieldNames)) ++ l(treeify(p.name, escapeUnicode, showFieldNames)) ++
Expand Down Expand Up @@ -153,10 +167,12 @@ class AstPrinter(traceOpinions: Boolean, traceAstSimple: Boolean, traceQuats: Qu

case _ => super.treeify(x, escapeUnicode, showFieldNames)
}
}

private def TreeApplyList(prefix: String, body: List[Tree]) = Tree.Apply(prefix, body.iterator)

private def l(trees: Tree*): List[Tree] = List[Tree](trees: _*)
private def ltree(trees: List[Tree]) = Tree.Apply("List", trees.iterator)

def apply(x: Any): fansi.Str =
fansi.Str.join(this.tokenize(x).toSeq)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,32 @@ trait OnConflictSupport {
strategy: NamingStrategy,
idiomContext: IdiomContext
): Tokenizer[OnConflict] = {
val entityAlias = "t"

val customEntityTokenizer = Tokenizer[Entity] { case Entity.Opinionated(name, _, _, renameable) =>
stmt"INTO ${renameable.fixedOr(name.token)(strategy.table(name).token)} AS t"
stmt"INTO ${renameable.fixedOr(name.token)(strategy.table(name).token)} AS ${entityAlias.token}"
}

val customAstTokenizer =
Tokenizer.withFallback[Ast](self.astTokenizer(_, strategy, idiomContext)) {
case Property(_: OnConflict.Excluded, value) => stmt"EXCLUDED.${value.token}"

// At first glance it might be hard to understand why this is doing `case OnConflict.Existing(a) => stmt"${entityAlias}"`
// but consider that this is a situation where multiple aliases are used in multiple update clauses e.g. the `tt` in the below example
// wouldn't even exist as a variable because in the query produced (also below) it would not even exist
// i.e. since the table will be aliased as the first `existing table` variable i.e. `t`.
// The second one `tt` wouldn't even exist.
// ins.onConflictUpdate(_.i, _.s)(
// (t, e) => t.l -> foo(t.l, e.l), (tt, ee) => tt.l -> bar(tt.l, ee.l)
// )
// This doesn't exist!!
// v
// > INSERT INTO TestEntity AS t (s,i,l,o,b) VALUES (?, ?, ?, ?, ?) ON CONFLICT (i,s) DO UPDATE SET l = foo(t.l, EXCLUDED.l), l = bar(tt.l, EXCLUDED.l)
//
// So instead of the situation we use the original alias of the table as it was computed by Quill i.e. `t`.
// See the "cols target - update + infix" example for more detail
case _: OnConflict.Excluded => stmt"EXCLUDED"
case OnConflict.Existing(a) => stmt"${a.token}"
case _: OnConflict.Existing => stmt"${entityAlias.token}"
case a: Action =>
self.actionTokenizer(customEntityTokenizer)(actionAstTokenizer, strategy, idiomContext).token(a)
}
Expand Down
Loading

0 comments on commit ba5920d

Please sign in to comment.