-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support of upsert (insert or update, on conflict) for Postgres an…
…d MySQL
- Loading branch information
Showing
36 changed files
with
925 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
quill-async-mysql/src/test/scala/io/getquill/context/async/mysql/ConflictAsyncSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.getquill.context.async.mysql | ||
|
||
import io.getquill.context.sql.ConflictSpec | ||
|
||
import scala.concurrent.ExecutionContext.Implicits.global | ||
|
||
class ConflictAsyncSpec extends ConflictSpec { | ||
val ctx = testContext | ||
import ctx._ | ||
|
||
override protected def beforeAll(): Unit = { | ||
await(ctx.run(qr1.delete)) | ||
() | ||
} | ||
|
||
"INSERT IGNORE" in { | ||
import `onConflictIgnore`._ | ||
await(ctx.run(testQuery1)) mustEqual res1 | ||
await(ctx.run(testQuery2)) mustEqual res2 | ||
await(ctx.run(testQuery3)) mustEqual res3 | ||
} | ||
|
||
"ON DUPLICATE KEY UPDATE i=i " in { | ||
import `onConflictIgnore(_.i)`._ | ||
await(ctx.run(testQuery1)) mustEqual res1 | ||
await(ctx.run(testQuery2)) mustEqual res2 | ||
await(ctx.run(testQuery3)) mustEqual res3 | ||
} | ||
|
||
"ON DUPLICATE KEY UPDATE ..." in { | ||
import `onConflictUpdate((t, e) => ...)`._ | ||
await(ctx.run(testQuery(e1))) mustEqual res1 | ||
await(ctx.run(testQuery(e2))) mustEqual res2 + 1 | ||
await(ctx.run(testQuery(e3))) mustEqual res3 + 1 | ||
await(ctx.run(testQuery4)) mustEqual res4 | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...-async-postgres/src/test/scala/io/getquill/context/async/postgres/ConflictAsyncSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package io.getquill.context.async.postgres | ||
|
||
import io.getquill.context.sql.ConflictSpec | ||
|
||
import scala.concurrent.ExecutionContext.Implicits.global | ||
|
||
class ConflictAsyncSpec extends ConflictSpec { | ||
val ctx = testContext | ||
import ctx._ | ||
|
||
override protected def beforeAll(): Unit = { | ||
await(ctx.run(qr1.delete)) | ||
() | ||
} | ||
|
||
"ON CONFLICT DO NOTHING" in { | ||
import `onConflictIgnore`._ | ||
await(ctx.run(testQuery1)) mustEqual res1 | ||
await(ctx.run(testQuery2)) mustEqual res2 | ||
await(ctx.run(testQuery3)) mustEqual res3 | ||
} | ||
|
||
"ON CONFLICT (i) DO NOTHING" in { | ||
import `onConflictIgnore(_.i)`._ | ||
await(ctx.run(testQuery1)) mustEqual res1 | ||
await(ctx.run(testQuery2)) mustEqual res2 | ||
await(ctx.run(testQuery3)) mustEqual res3 | ||
} | ||
|
||
"ON CONFLICT (i) DO UPDATE ..." in { | ||
import `onConflictUpdate(_.i)((t, e) => ...)`._ | ||
await(ctx.run(testQuery(e1))) mustEqual res1 | ||
await(ctx.run(testQuery(e2))) mustEqual res2 | ||
await(ctx.run(testQuery(e3))) mustEqual res3 | ||
await(ctx.run(testQuery4)) mustEqual res4 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.