Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/typelevel/skunk
Browse files Browse the repository at this point in the history
  • Loading branch information
mpilquist committed Jan 23, 2024
2 parents 2abde69 + d8da977 commit ed5ae45
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 27 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ jobs:

- name: Upload target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/series/0.6.x')
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-${{ matrix.scala }}-${{ matrix.project }}
path: targets.tar
Expand Down Expand Up @@ -138,7 +138,7 @@ jobs:
docker-compose up -d
- name: Download target directories (2.13, skunkJS)
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13-skunkJS

Expand All @@ -148,7 +148,7 @@ jobs:
rm targets.tar
- name: Download target directories (2.13, skunkJVM)
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13-skunkJVM

Expand All @@ -158,7 +158,7 @@ jobs:
rm targets.tar
- name: Download target directories (2.13, skunkNative)
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13-skunkNative

Expand All @@ -168,7 +168,7 @@ jobs:
rm targets.tar
- name: Download target directories (3, skunkJS)
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-3-skunkJS

Expand All @@ -178,7 +178,7 @@ jobs:
rm targets.tar
- name: Download target directories (3, skunkJVM)
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-3-skunkJVM

Expand All @@ -188,7 +188,7 @@ jobs:
rm targets.tar
- name: Download target directories (3, skunkNative)
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-3-skunkNative

Expand Down
2 changes: 1 addition & 1 deletion bin/local
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ esac
export SERVER_KEY=$(cat world/server.key)
export SERVER_CERT=$(cat world/server.crt)

docker-compose $CMD $EXTRA_FLAGS
docker compose $CMD $EXTRA_FLAGS
10 changes: 5 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ ThisBuild / mimaBinaryIssueFilters ++= List(
)

// This is used in a couple places
lazy val fs2Version = "3.9.3"
lazy val fs2Version = "3.9.4"
lazy val openTelemetryVersion = "1.29.0"
lazy val otel4sVersion = "0.4.0"
lazy val refinedVersion = "0.11.0"
Expand Down Expand Up @@ -111,7 +111,7 @@ lazy val core = crossProject(JVMPlatform, JSPlatform, NativePlatform)
description := "Tagless, non-blocking data access library for Postgres.",
libraryDependencies ++= Seq(
"org.typelevel" %%% "cats-core" % "2.10.0",
"org.typelevel" %%% "cats-effect" % "3.5.2",
"org.typelevel" %%% "cats-effect" % "3.5.3",
"co.fs2" %%% "fs2-core" % fs2Version,
"co.fs2" %%% "fs2-io" % fs2Version,
"org.scodec" %%% "scodec-bits" % "1.1.38",
Expand Down Expand Up @@ -170,7 +170,7 @@ lazy val postgis = crossProject(JVMPlatform, JSPlatform, NativePlatform)
name := "skunk-postgis",
libraryDependencies ++= Seq(
"org.typelevel" %%% "cats-parse" % "1.0.0"
)
),
)

lazy val tests = crossProject(JVMPlatform, JSPlatform, NativePlatform)
Expand All @@ -188,7 +188,7 @@ lazy val tests = crossProject(JVMPlatform, JSPlatform, NativePlatform)
"org.typelevel" %%% "munit-cats-effect" % "2.0.0-M4",
"org.typelevel" %%% "cats-free" % "2.10.0",
"org.typelevel" %%% "cats-laws" % "2.10.0",
"org.typelevel" %%% "cats-effect-testkit" % "3.5.2",
"org.typelevel" %%% "cats-effect-testkit" % "3.5.3",
"org.typelevel" %%% "discipline-munit" % "2.0.0-M3",
"org.typelevel" %%% "cats-time" % "0.5.1",
"eu.timepit" %%% "refined-cats" % refinedVersion,
Expand Down Expand Up @@ -286,4 +286,4 @@ lazy val docs = project
}
)

// ci
// ci
13 changes: 10 additions & 3 deletions modules/core/shared/src/main/scala/Fragment.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,18 @@ final case class Fragment[A](
def stripMargin: Fragment[A] = stripMargin('|')

def stripMargin(marginChar: Char): Fragment[A] = {
val ps = parts.map {
val head = parts.headOption
val tail = parts.tail
val ps = head.map {
_.bimap(
_.stripMargin(marginChar).replaceAll("\n", " "),
_.map(_.stripMargin(marginChar).replaceAll("\n", " "))
_.stripMargin(marginChar),
_.map(_.stripMargin(marginChar))
)
}.toList ++ tail.map {
_.bimap(
str => str.takeWhile(_ != '\n') + str.dropWhile(_ != '\n').stripMargin(marginChar),
_.map(str => str.takeWhile(_ != '\n') + str.dropWhile(_ != '\n').stripMargin(marginChar))
)
}
Fragment(ps, encoder, origin)
}
Expand Down
1 change: 1 addition & 0 deletions modules/core/shared/src/main/scala/data/Completion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ object Completion {
case object Grant extends Completion
case object Revoke extends Completion
case object AlterIndex extends Completion
case class Merge(count: Int) extends Completion
// more ...

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ object CommandComplete {
val Update: Regex = """UPDATE (\d+)""".r
val Insert: Regex = """INSERT (\d+ \d+)""".r
val Copy: Regex = """COPY (\d+)""".r
val Merge: Regex = """MERGE (\d+)""".r
}

//TODO: maybe make lazy val
Expand Down Expand Up @@ -103,6 +104,7 @@ object CommandComplete {
case "GRANT" => apply(Completion.Grant)
case "REVOKE" => apply(Completion.Revoke)
case "ALTER INDEX" => apply(Completion.AlterIndex)
case Patterns.Merge(s) => apply(Completion.Merge(s.toInt))
// more .. fill in as we hit them

case s => apply(Completion.Unknown(s))
Expand Down
27 changes: 27 additions & 0 deletions modules/tests/shared/src/test/scala/CommandTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ class CommandTest extends SkunkTest {
WHERE id = $int4
""".command

val mergeCity: Command[Int] =
sql"""
MERGE INTO city
USING (VALUES ($int4)) t(city_id) ON t.city_id = city.id
WHEN MATCHED THEN DELETE
""".command

val createTable: Command[Void] =
sql"""
CREATE TABLE IF NOT EXISTS earth (
Expand Down Expand Up @@ -541,6 +548,26 @@ class CommandTest extends SkunkTest {
} yield "ok"
}

sessionTest("merge a record") { s =>
s.unique(sql"SHOW server_version".query(skunk.codec.all.text))
.flatMap { version =>
val majorVersion = version.substring(0, 2).toInt
if (majorVersion >= 15) {
for {
c <- s.prepare(insertCity).flatMap(_.execute(Garin))
_ <- assert("completion", c == Completion.Insert(1))
c <- s.prepare(mergeCity).flatMap(_.execute(Garin.id))
_ <- assert("merge", c == Completion.Merge(1))
c <- s.prepare(selectCity).flatMap(_.option(Garin.id))
_ <- assert("read", c == None)
_ <- s.execute(deleteCity)(Garin.id)
_ <- s.assertHealthy
} yield "ok"
}
else IO.pure("skip")
}
}

sessionTest("pipe") { s =>
for {
_ <- s.execute(sql"delete from city where name like 'Pipe%'".command)
Expand Down
23 changes: 17 additions & 6 deletions modules/tests/shared/src/test/scala/FragmentTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,26 @@ class FragmentTest extends SkunkTest {

pureTest("stripMargin") {
val f = sql"""select
|$int4
|""".stripMargin
f.sql.trim == sql"select $int4".sql
|$int4
|""".stripMargin
f.sql == """select
|$1
|""".stripMargin
}

pureTest("stripMargin with char") {
val f = sql"""select
^$int4
^""".stripMargin('^')
f.sql.trim == sql"select $int4".sql
^$int4
^""".stripMargin('^')
f.sql == """select
^$1
^""".stripMargin('^')
}

pureTest("stripMargin respects intermediate pipes") {
val f = sql"""|select ${text} || 'foo'
|2""".stripMargin
f.sql == """select $1 || 'foo'
|2""".stripMargin
}
}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.9.7
sbt.version=1.9.8
8 changes: 4 additions & 4 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ ThisBuild / libraryDependencySchemes ++= Seq(
"org.scala-lang.modules" %% "scala-xml" % VersionScheme.Always
)

addSbtPlugin("org.typelevel" % "sbt-typelevel" % "0.6.3")
addSbtPlugin("org.typelevel" % "sbt-typelevel-site" % "0.6.3")
addSbtPlugin("org.typelevel" % "sbt-typelevel" % "0.6.5")
addSbtPlugin("org.typelevel" % "sbt-typelevel-site" % "0.6.5")
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.4")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.9")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.14.0")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.16")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.15.0")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.17")
addSbtPlugin("com.armanbilge" % "sbt-scala-native-config-brew-github-actions" % "0.2.0-RC1")

0 comments on commit ed5ae45

Please sign in to comment.