Skip to content

Commit 3f8992b

Browse files
authored
Support INSERT OR REPLACE DSL (#120)
* Support `INSERT OR REPLACE` DSL, update AGP version, and consolidate CI publishing scripts. * Fix CI's trigger condictions
1 parent fc78f7b commit 3f8992b

12 files changed

Lines changed: 135 additions & 93 deletions

File tree

.github/workflows/build.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ name: Build & Test
33
on:
44
push:
55
branches:
6-
- '*'
6+
- main
7+
- 'release/**'
78
pull_request:
8-
branches:
9-
- '*'
9+
branches:
10+
- main
11+
- 'release/**'
1012

1113
jobs:
1214

.github/workflows/publish.yml

Lines changed: 3 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -41,87 +41,13 @@ jobs:
4141
${{ runner.os }}-konan-
4242
4343
- name: Build sqllin-driver
44-
run: ./gradlew :sqllin-driver:assemble -PonCICD
45-
46-
- name: Build sqllin-dsl
47-
run: ./gradlew :sqllin-dsl:assemble -PonCICD
48-
49-
- name: Publish to MavenCentral
50-
run: ./publish_apple_android_jvm.sh
51-
52-
build-on-windows:
53-
runs-on: windows-latest
54-
timeout-minutes: 60
55-
56-
steps:
57-
- name: Checkout
58-
uses: actions/checkout@v4
59-
60-
- name: Validate Gradle Wrapper
61-
uses: gradle/actions/wrapper-validation@v3
62-
63-
- name: Set up JDK 21
64-
uses: actions/setup-java@v4
65-
with:
66-
distribution: 'zulu'
67-
java-version: 21
68-
69-
- name: Setup Gradle
70-
uses: gradle/actions/setup-gradle@v4
71-
72-
- name: Cache Kotlin/Native
73-
uses: actions/cache@v4
74-
with:
75-
path: ~/.konan
76-
key: ${{ runner.os }}-konan-${{ hashFiles('**/*.gradle.kts') }}
77-
restore-keys: |
78-
${{ runner.os }}-konan-
79-
80-
- name: Build sqllin-driver
81-
run: ./gradlew :sqllin-driver:mingwX64MainKlibrary
82-
83-
- name: Build sqllin-dsl
84-
run: ./gradlew :sqllin-dsl:mingwX64MainKlibrary
85-
86-
- name: Publish to MavenCentral
87-
run: ./gradlew :sqllin-driver:publishMingwX64PublicationToMavenCentralRepository && ./gradlew :sqllin-dsl:publishMingwX64PublicationToMavenCentralRepository
88-
89-
build-on-linux:
90-
runs-on: ubuntu-latest
91-
timeout-minutes: 60
92-
93-
steps:
94-
- name: Checkout
95-
uses: actions/checkout@v4
96-
97-
- name: Validate Gradle Wrapper
98-
uses: gradle/actions/wrapper-validation@v3
99-
100-
- name: Set up JDK 21
101-
uses: actions/setup-java@v4
102-
with:
103-
distribution: 'zulu'
104-
java-version: 21
105-
106-
- name: Setup Gradle
107-
uses: gradle/actions/setup-gradle@v4
108-
109-
- name: Cache Kotlin/Native
110-
uses: actions/cache@v4
111-
with:
112-
path: ~/.konan
113-
key: ${{ runner.os }}-konan-${{ hashFiles('**/*.gradle.kts') }}
114-
restore-keys: |
115-
${{ runner.os }}-konan-
116-
117-
- name: Build sqllin-driver
118-
run: ./gradlew :sqllin-driver:assemble -PonCICD
44+
run: ./gradlew :sqllin-driver:assemble
11945

12046
- name: Build sqllin-processor
12147
run: ./gradlew :sqllin-processor:assemble
12248

12349
- name: Build sqllin-dsl
124-
run: ./gradlew :sqllin-dsl:assemble -PonCICD
50+
run: ./gradlew :sqllin-dsl:assemble
12551

12652
- name: Publish to MavenCentral
127-
run: ./publish_linux_processor.sh
53+
run: ./publish_all.sh

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
- Date format: YYYY-MM-dd
44

5-
## 2.3.0 / 2026-05-16
5+
## 2.3.0 / 2026-05-xx
66

77
### All
88

99
* Update `Kotlin`'s version to `2.3.21`
10-
* Update `AGP`'s version to `9.0.0`, migrated from `com.android.library` plugin to `com.android.kotlin.multiplatform.library`
10+
* Update `AGP`'s version to `9.2.1`, migrated from `com.android.library` plugin to `com.android.kotlin.multiplatform.library`
1111
* Update `kotlinx.serialization`'s version to `1.11.0`
1212
* Update `kotlinx.coroutines`'s version to `1.11.0`
1313
* Fix documentation: Android minimum supported version has been `7.0+` (API 24) since `2.0.0`, the README incorrectly stated `6.0+`

ROADMAP.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
## High Priority
44

5-
* Support FOREIGN KEY DSL (2.2.0 ✅)
6-
* Support CREATE INDEX DSL (2.2.0 ✅)
75
* Support INSERT OR REPLACE
86

97
## Medium Priority
@@ -18,4 +16,9 @@
1816
## Low Priority
1917

2018
* Support store instances of kotlinx.datetime
21-
* Support CHECK keyword
19+
* Support CHECK keyword
20+
21+
## Supported
22+
23+
* Support FOREIGN KEY DSL (2.2.0 ✅)
24+
* Support CREATE INDEX DSL (2.2.0 ✅)
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# Publish artifacts on macOS env
2-
./gradlew :sqllin-driver:publishAllPublicationsToMavenCentralRepository -PonCICD
3-
./gradlew :sqllin-dsl:publishAllPublicationsToMavenCentralRepository -PonCICD
2+
./gradlew :sqllin-driver:publishAllPublicationsToMavenCentralRepository
3+
./gradlew :sqllin-dsl:publishAllPublicationsToMavenCentralRepository
4+
./gradlew :sqllin-processor:publishMavenPublicationToMavenCentralRepository

publish_linux_processor.sh

Lines changed: 0 additions & 6 deletions
This file was deleted.

sqllin-dsl-test/src/androidDeviceTest/kotlin/com/ctrip/sqllin/dsl/test/AndroidTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ class AndroidTest {
6767
@Test
6868
fun testInsertWithId() = commonTest.testInsertWithId()
6969

70+
@Test
71+
fun testInsertOrReplace() = commonTest.testInsertOrReplace()
72+
7073
@Test
7174
fun testCreateInDatabaseScope() = commonTest.testCreateInDatabaseScope()
7275

sqllin-dsl-test/src/commonMain/kotlin/com/ctrip/sqllin/dsl/test/CommonBasicTest.kt

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,58 @@ class CommonBasicTest(private val path: DatabasePath) {
633633
}
634634
}
635635

636+
@OptIn(AdvancedInsertAPI::class)
637+
fun testInsertOrReplace() {
638+
Database(getNewAPIDBConfig()).databaseAutoClose { database ->
639+
// Insert an initial entity with a known ID
640+
val original = PersonWithId(id = 100L, name = "Eve", age = 28)
641+
database {
642+
PersonWithIdTable { table ->
643+
table INSERT_WITH_ID original
644+
}
645+
}
646+
647+
lateinit var selectStatement: SelectStatement<PersonWithId>
648+
database {
649+
selectStatement = PersonWithIdTable SELECT X
650+
}
651+
assertEquals(1, selectStatement.getResults().size)
652+
assertEquals(100L, selectStatement.getResults().first().id)
653+
assertEquals("Eve", selectStatement.getResults().first().name)
654+
655+
// INSERT_OR_REPLACE with the same PK — should replace the existing row
656+
val replacement = PersonWithId(id = 100L, name = "Eve Updated", age = 29)
657+
database {
658+
PersonWithIdTable { table ->
659+
table INSERT_OR_REPLACE replacement
660+
}
661+
}
662+
663+
database {
664+
selectStatement = PersonWithIdTable SELECT X
665+
}
666+
val resultsAfterReplace = selectStatement.getResults()
667+
assertEquals(1, resultsAfterReplace.size)
668+
assertEquals(100L, resultsAfterReplace.first().id)
669+
assertEquals("Eve Updated", resultsAfterReplace.first().name)
670+
assertEquals(29, resultsAfterReplace.first().age)
671+
672+
// INSERT_OR_REPLACE with a new entity (null ID) — should insert without conflict
673+
val newEntity = PersonWithId(id = null, name = "Frank", age = 35)
674+
database {
675+
PersonWithIdTable { table ->
676+
table INSERT_OR_REPLACE newEntity
677+
}
678+
}
679+
680+
database {
681+
selectStatement = PersonWithIdTable SELECT X
682+
}
683+
assertEquals(2, selectStatement.getResults().size)
684+
assertEquals(true, selectStatement.getResults().any { it.name == "Frank" })
685+
}
686+
}
687+
636688
fun testCreateInDatabaseScope() {
637689
Database(getNewAPIDBConfig()).databaseAutoClose { database ->
638690
val person = PersonWithId(id = null, name = "Grace", age = 40)

sqllin-dsl-test/src/jvmTest/kotlin/com/ctrip/sqllin/dsl/test/JvmTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ class JvmTest {
6161
@Test
6262
fun testInsertWithId() = commonTest.testInsertWithId()
6363

64+
@Test
65+
fun testInsertOrReplace() = commonTest.testInsertOrReplace()
66+
6467
@Test
6568
fun testCreateInDatabaseScope() = commonTest.testCreateInDatabaseScope()
6669

sqllin-dsl-test/src/nativeTest/kotlin/com/ctrip/sqllin/dsl/test/NativeTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ class NativeTest {
7777
@Test
7878
fun testInsertWithId() = commonTest.testInsertWithId()
7979

80+
@Test
81+
fun testInsertOrReplace() = commonTest.testInsertOrReplace()
82+
8083
@Test
8184
fun testCreateInDatabaseScope() = commonTest.testCreateInDatabaseScope()
8285

0 commit comments

Comments
 (0)