Skip to content

Commit 71e0763

Browse files
mysql tests
1 parent af036e9 commit 71e0763

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ buildscript {
1212

1313
allprojects {
1414
group = "me.liuwj.ktorm"
15-
version = "1.0"
15+
version = "1.1"
1616
}
1717

1818
subprojects { project ->

ktorm-support-mysql/src/test/kotlin/me/liuwj/ktorm/support/mysql/MySqlTest.kt

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ import me.liuwj.ktorm.BaseTest
44
import me.liuwj.ktorm.database.Database
55
import me.liuwj.ktorm.database.useConnection
66
import me.liuwj.ktorm.dsl.*
7+
import me.liuwj.ktorm.entity.count
8+
import me.liuwj.ktorm.entity.findById
79
import me.liuwj.ktorm.entity.sumBy
810
import org.junit.Test
11+
import java.time.LocalDate
912

1013
/**
1114
* Created by vince on Dec 12, 2018.
@@ -47,4 +50,59 @@ class MySqlTest : BaseTest() {
4750

4851
assert(Employees.sumBy { it.salary } == 800L)
4952
}
53+
54+
@Test
55+
fun testBulkInsert() {
56+
Employees.bulkInsert {
57+
item {
58+
it.name to "jerry"
59+
it.job to "trainee"
60+
it.managerId to 1
61+
it.hireDate to LocalDate.now()
62+
it.salary to 50
63+
it.departmentId to 1
64+
}
65+
item {
66+
it.name to "linda"
67+
it.job to "assistant"
68+
it.managerId to 3
69+
it.hireDate to LocalDate.now()
70+
it.salary to 100
71+
it.departmentId to 2
72+
}
73+
}
74+
75+
assert(Employees.count() == 6)
76+
}
77+
78+
@Test
79+
fun testInsertOrUpdate() {
80+
Employees.insertOrUpdate {
81+
it.id to 1
82+
it.name to "vince"
83+
it.job to "engineer"
84+
it.salary to 1000
85+
it.hireDate to LocalDate.now()
86+
it.departmentId to 1
87+
88+
onDuplicateKey {
89+
it.salary to it.salary + 900
90+
}
91+
}
92+
Employees.insertOrUpdate {
93+
it.id to 5
94+
it.name to "vince"
95+
it.job to "engineer"
96+
it.salary to 1000
97+
it.hireDate to LocalDate.now()
98+
it.departmentId to 1
99+
100+
onDuplicateKey {
101+
it.salary to it.salary + 900
102+
}
103+
}
104+
105+
assert(Employees.findById(1)!!.salary == 1000L)
106+
assert(Employees.findById(5)!!.salary == 1000L)
107+
}
50108
}

0 commit comments

Comments
 (0)