Skip to content

Commit

Permalink
Add merge completion case
Browse files Browse the repository at this point in the history
  • Loading branch information
massimosiani committed Jan 10, 2024
1 parent 6696bcc commit d73e04f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
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
19 changes: 19 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,18 @@ class CommandTest extends SkunkTest {
} yield "ok"
}

sessionTest("merge a record") { s =>
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.assertHealthy
} yield "ok"
}

sessionTest("pipe") { s =>
for {
_ <- s.execute(sql"delete from city where name like 'Pipe%'".command)
Expand Down

0 comments on commit d73e04f

Please sign in to comment.