You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/site/markdown/docs/kotlinMyBatis3.md
+4-3Lines changed: 4 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -113,7 +113,7 @@ val rows = mapper.count {
113
113
}
114
114
```
115
115
116
-
There is also an extension method that can be used to count all rows in a table:
116
+
There is also a method that can be used to count all rows in a table:
117
117
118
118
```kotlin
119
119
val rows = mapper.count { allRows() }
@@ -385,11 +385,12 @@ val rows = mapper.update {
385
385
```
386
386
## Join Support
387
387
388
-
There are extension functions that support building a reusable select method based on a join. In this way, you can create the start of the select statement (the column list and join specifications) and allow the user to supply where clauses and other parts of a select statement. For example, you could code a mapper extension method like this:
388
+
There are functions that support building a reusable select method based on a join. In this way, you can create the start of the select statement (the column list and join specifications) and allow the user to supply where clauses and other parts of a select statement. For example, you could code a mapper extension method like this:
389
389
390
390
```kotlin
391
391
fun PersonWithAddressMapper.select(completer:SelectCompleter): List<PersonWithAddress> {
392
-
val start = select(columnList).from(Person, "p") {
Copy file name to clipboardExpand all lines: src/site/markdown/docs/kotlinSpring.md
+20-19Lines changed: 20 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -73,18 +73,16 @@ The DSL for count methods looks like this:
73
73
}
74
74
75
75
// count(column)
76
-
val countStatement =countColumn(lastName).from(Person) { // countStatement is a SelectStatementProvider
77
-
allRows()
76
+
val countStatement =count(lastName) { // countStatement is a SelectStatementProvider
77
+
from(Person)
78
78
}
79
79
80
80
// count(distinct column)
81
-
val countStatement =countDistinctColumn(lastName).from(Person) { // countStatement is a SelectStatementProvider
82
-
allRows()
81
+
val countStatement =countDistinct(lastName) { // countStatement is a SelectStatementProvider
82
+
from(Person)
83
83
}
84
84
```
85
85
86
-
Note the somewhat awkward method names `countColumn`, and `countDistinctColumn`. The methods are named this way to avoid a name collision with other methods in the `SqlBuilder`. This awkwardness can be avoided by using the one-step method shown below.
87
-
88
86
These methods create a `SelectStatementProvider` that can be executed with an extension method for `NamedParameterJdbcTemplate` like this:
89
87
90
88
```kotlin
@@ -99,16 +97,18 @@ This is the two-step execution process. This can be combined into a single step
99
97
where(id, isLessThan(4))
100
98
}
101
99
102
-
val rows = template.count(lastName).from(Person) {
100
+
val rows = template.count(lastName) {
101
+
from(Person)
103
102
where(id, isLessThan(4))
104
103
}
105
104
106
-
val rows = template.countDistinct(lastName).from(Person) {
105
+
val rows = template.countDistinct(lastName) {
106
+
from(Person)
107
107
where(id, isLessThan(4))
108
108
}
109
109
```
110
110
111
-
There is also an extension method that can be used to count all rows in a table:
111
+
There is also a method that can be used to count all rows in a table:
112
112
113
113
```kotlin
114
114
val rows = template.countFrom(Person) {
@@ -143,7 +143,7 @@ This is the two-step execution process. This can be combined into a single step
143
143
}
144
144
```
145
145
146
-
There is also an extension method that can be used to count all rows in a table:
146
+
There is also a method that can be used to count all rows in a table:
147
147
148
148
```kotlin
149
149
val rows = template.deleteFrom(Person) {
@@ -404,7 +404,8 @@ The DSL for select methods looks like this:
404
404
405
405
```kotlin
406
406
val selectStatement = select(id, firstName, lastName, birthDate, employed, occupation, // selectStatement is a SelectStatementProvider
407
-
addressId).from(Person) {
407
+
addressId) {
408
+
from(Person)
408
409
where(id, isLessThan(5))
409
410
and(id, isLessThan(4)) {
410
411
and(id, isLessThan(3)) {
@@ -437,8 +438,8 @@ Note that you must provide a row mapper to tell Spring JDBC how to create result
437
438
This is the two-step execution process. This can be combined into a single step with code like the following:
438
439
439
440
```kotlin
440
-
val rows = template.select(id, firstName, lastName, birthDate, employed, occupation, addressId)
@@ -461,8 +462,8 @@ This is the two-step execution process. This can be combined into a single step
461
462
There are similar methods for selecting a single row, or executing a select distinct query. For example, you could implement a "select by primary key" method using code like this:
462
463
463
464
```kotlin
464
-
val record = template.selectOne(id, firstName, lastName, birthDate, employed, occupation, addressId)
465
-
.from(Person) {
465
+
val record = template.selectOne(id, firstName, lastName, birthDate, employed, occupation, addressId) {
466
+
from(Person)
466
467
where(id, isEqualTo(key))
467
468
}.withRowMapper { rs, _ ->
468
469
PersonRecord().apply {
@@ -479,12 +480,12 @@ There are similar methods for selecting a single row, or executing a select dist
479
480
480
481
In this case, the data type for `record` would be `PersonRecord?` - a nullable value.
481
482
482
-
There is also an extension method that can be used to select all rows in a table:
483
+
There is also an optional method that can be used to select all rows in a table:
483
484
484
485
```kotlin
485
-
val rows = template.select(id, firstName, lastName, birthDate, employed, occupation, addressId)
0 commit comments