Skip to content
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 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
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 @@ -64,6 +64,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 @@ -102,6 +103,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 @@ -524,6 +531,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