Skip to content

Commit 35f8117

Browse files
committed
Join documentation updates
1 parent c55db90 commit 35f8117

File tree

3 files changed

+30
-18
lines changed

3 files changed

+30
-18
lines changed

CHANGELOG.md

+8-6
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,19 @@ GitHub milestone: [https://github.com/mybatis/mybatis-dynamic-sql/issues?q=miles
2020
([#438](https://github.com/mybatis/mybatis-dynamic-sql/pull/438))
2121
4. Major update to the Kotlin where clause DSL. Where clauses now support the "group" and "not" features from above. In
2222
addition, the where clause DSL has been fully updated to make it feel more like natural SQL. The previous version
23-
of the where clause DSL yielded almost unreadable code when the "group" and "not" functions were added. This update
24-
is better all around and yields a DSL that is very similar to native SQL. The new DSL includes many Kotlin DSL
25-
construction features including infix functions, operator overloads, and functions with receivers. We believe it
26-
will be well worth the effort to migrate to the new DSL. The prior where clause DSL remains in the library for now,
27-
but is deprecated. It will be removed in version 1.5.0 of the library. Documentation for the new DSL is here:
28-
https://github.com/mybatis/mybatis-dynamic-sql/blob/master/src/site/markdown/docs/kotlinWhereClauses.md
23+
of the where clause DSL would have yielded almost unreadable code had the "group" and "not" functions been added.
24+
This update is better all around and yields a DSL that is very similar to native SQL. The new DSL includes many
25+
Kotlin DSL construction features including infix functions, operator overloads, and functions with receivers.
26+
We believe it will be well worth the effort to migrate to the new DSL. The prior where clause DSL remains in the
27+
library for now, but is deprecated. It will be removed in version 1.5.0 of the library. Documentation for the new
28+
DSL is here: https://github.com/mybatis/mybatis-dynamic-sql/blob/master/src/site/markdown/docs/kotlinWhereClauses.md
2929
([#442](https://github.com/mybatis/mybatis-dynamic-sql/pull/442))
3030
5. General cleanup of the Kotlin DSL. The Kotlin DSL functions are now mostly Unit functions. This should have
3131
no impact on most users and is source code compatible with prior versions of the library when the library was used
3232
as described in the documentation. This change greatly simplifies the type hierarchy of the Kotlin builders.
3333
([#446](https://github.com/mybatis/mybatis-dynamic-sql/pull/446))
34+
6. Minor update the Kotlin join DSL to make it closer to natural SQL. The existing join methods are deprecated and
35+
will be removed in version 1.5.0.
3436

3537
## Release 1.3.1 - December 18, 2021
3638

src/site/markdown/docs/kotlinMyBatis3.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ fun PersonWithAddressMapper.select(completer: SelectCompleter): List<PersonWithA
922922
) {
923923
from(person, "p")
924924
fullJoin(address) {
925-
on(person.addressId, equalTo(address.id))
925+
on(person.addressId) equalTo address.id
926926
}
927927
completer()
928928
}.run(this::selectMany)

src/site/markdown/docs/kotlinOverview.md

+21-11
Original file line numberDiff line numberDiff line change
@@ -396,25 +396,35 @@ This method creates models or providers depending on which package is used:
396396
Select statement support enables the creation of methods that execute a query allowing a user to specify a where clause,
397397
join specifications, order by clauses, group by clauses, pagination clauses, etc.
398398

399-
The DSL for select statements looks like this:
399+
The full DSL for select statements looks like this:
400400

401401
```kotlin
402-
val selectStatement = select(id, firstName, lastName, birthDate, employed, occupation, addressId) {
403-
from(person)
404-
where { id isLessThan 5 }
405-
and {
406-
id isLessThan 4
407-
and {
408-
id isLessThan 3
409-
or { id isLessThan 2 }
410-
}
402+
val selectStatement = select(orderMaster.orderId, orderMaster.orderDate, orderDetail.lineNumber,
403+
orderDetail.description, orderDetail.quantity
404+
) {
405+
from(orderMaster, "om")
406+
join(orderDetail, "od") {
407+
on(orderMaster.orderId) equalTo orderDetail.orderId
408+
and(orderMaster.orderId) equalTo orderDetail.orderId
411409
}
412-
orderBy(id)
410+
where { orderMaster.orderId isEqualTo 1 }
411+
or {
412+
orderMaster.orderId isEqualTo 2
413+
and { orderDetail.quantity isLessThan 6 }
414+
}
415+
orderBy(orderMaster.orderId)
413416
limit(3)
414417
}
415418
```
416419

420+
In a select statement you must specify a table in a `from` clause. Everything else is optional.
421+
422+
Multiple join clauses can be specified if you need to join additional tables. In a join clause, you must
423+
specify an `on` condition, and you may specify additional `and` conditions as necessary. Full, left, right, inner,
424+
and outer joins are supported.
425+
417426
Where clauses can be of arbitrary complexity and support all SQL operators including exists operators, subqueries, etc.
427+
You can nest `and`, `or`, and `not` clauses as necessary in where clauses.
418428

419429
There is also a method that will create a "distinct" query (`select distinct ...`) as follows:
420430

0 commit comments

Comments
 (0)