Skip to content

Commit b1d6a78

Browse files
committed
Update README example - remove deprecated methods
1 parent 7377db1 commit b1d6a78

File tree

1 file changed

+38
-36
lines changed

1 file changed

+38
-36
lines changed

README.md

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,63 +9,65 @@
99
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=mybatis_mybatis-dynamic-sql&metric=security_rating)](https://sonarcloud.io/dashboard?id=mybatis_mybatis-dynamic-sql)
1010

1111
## What Is This?
12-
This library is a general purpose SQL generator. Think of it as a typesafe and expressive SQL DSL (domain specific language),
13-
with support for rendering SQL formatted properly for MyBatis3 and Spring's NamedParameterJDBCTemplate.
12+
This library is a general purpose SQL generator. Think of it as a typesafe and expressive SQL DSL (domain specific
13+
language), with support for rendering SQL formatted properly for MyBatis3 and Spring's NamedParameterJDBCTemplate.
1414

1515
The library also contains extensions for Kotlin that enable an idiomatic Kotlin DSL for SQL.
1616

1717
The library will generate full DELETE, INSERT, SELECT, and UPDATE statements. The DSL implemented by the
18-
library is very similar to native SQL but it includes many functions that allow for very dynamic SQL statements.
19-
For example, a typical search can be coded with a query like this (the following code is Kotlin, but Java code is very similar):
18+
library is very similar to native SQL, but it includes many functions that allow for very dynamic SQL statements.
19+
For example, a typical search can be coded with a query like this (the following code is Kotlin, but Java code is very
20+
similar):
2021

2122
```kotlin
22-
fun search(id: String?, firstName: String?, lastName: String?) =
23-
select(Customer.id, Customer.firstName, Customer.lastName) {
23+
fun search(id_: String?, firstName_: String?, lastName_: String?) =
24+
select(id, firstName, lastName) {
2425
from(Customer)
25-
where { Customer.active.isTrue() }
26-
and { Customer.id (isEqualToWhenPresent(id).map{ it?.padStart(5, '0') }) }
27-
and { Customer.firstName (isLikeCaseInsensitiveWhenPresent(firstName)
28-
.map{ "%" + it.trim() + "%" }) }
29-
and { Customer.lastName (isLikeCaseInsensitiveWhenPresent(lastName)
30-
.map{ "%" + it.trim() + "%" }) }
31-
orderBy(Customer.lastName, Customer.firstName)
26+
where {
27+
active isEqualTo "Y"
28+
and { id(isEqualToWhenPresent(id_).map { it?.padStart(5, '0') }) }
29+
and { firstName(isLikeCaseInsensitiveWhenPresent(firstName_).map { "%" + it.trim() + "%" }) }
30+
and { lastName(isLikeCaseInsensitiveWhenPresent(lastName_).map { "%" + it.trim() + "%" }) }
31+
}
32+
orderBy(lastName, firstName)
3233
limit(500)
3334
}
3435
```
3536

3637
This query does quite a lot...
3738

3839
1. It is a search with three search criteria - any combination of search criteria can be used
39-
1. Only records with an active status will be returned
40-
1. If `id` is specified, it will be padded to length 5 with '0' at the beginning of the string
41-
1. If `firstName` is specified, it will be used in a case-insensitive search and SQL wildcards will be appended
42-
1. If `lastName` is specified, it will be used in a case-insensitive search and SQL wildcards will be appended
43-
1. The query results are limited to 500 rows
40+
2. Only records with an active status will be returned
41+
3. If `id_` is specified, it will be padded to length 5 with '0' at the beginning of the string
42+
4. If `firstName_` is specified, it will be used in a case-insensitive search and SQL wildcards will be appended
43+
5. If `lastName_` is specified, it will be used in a case-insensitive search and SQL wildcards will be appended
44+
6. The query results are limited to 500 rows
4445

45-
Using the dynamic SQL features of the library eliminates a lot of code that would be required for checking nulls, adding wild cards, etc. This query clearly expresses the intent of the search in just a few lines.
46+
Using the dynamic SQL features of the library eliminates a lot of code that would be required for checking nulls,
47+
adding wild cards, etc. This query clearly expresses the intent of the search in just a few lines.
4648

4749
See the following pages for detailed information:
4850

49-
| Page | Comments|
50-
|------|---------|
51-
|[Quick Start](src/site/markdown/docs/quickStart.md) | Shows a complete example of building code for this library |
52-
|[MyBatis3 Support](src/site/markdown/docs/mybatis3.md) | Information about specialized support for [MyBatis3](https://github.com/mybatis/mybatis-3). The examples on this page are similar to the code generated by [MyBatis Generator](https://github.com/mybatis/generator) |
53-
|[Kotlin Support with MyBatis3](src/site/markdown/docs/kotlinMyBatis3.md) | Information about the Kotlin extensions and Kotlin DSL when using MyBatis3 as the runtime |
54-
|[Spring Support](src/site/markdown/docs/spring.md) | Information about specialized support for Spring JDBC Templates |
55-
|[Kotlin Support with Spring](src/site/markdown/docs/kotlinSpring.md) | Information about the Kotlin extensions and Kotlin DSL when using Spring JDBC Template as the runtime |
56-
|[Spring Batch Support](src/site/markdown/docs/springBatch.md) | Information about specialized support for Spring Batch using the [MyBatis Spring Integration](https://github.com/mybatis/spring) |
51+
| Page | Comments |
52+
|--------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
53+
| [Quick Start](src/site/markdown/docs/quickStart.md) | Shows a complete example of building code for this library |
54+
| [MyBatis3 Support](src/site/markdown/docs/mybatis3.md) | Information about specialized support for [MyBatis3](https://github.com/mybatis/mybatis-3). The examples on this page are similar to the code generated by [MyBatis Generator](https://github.com/mybatis/generator) |
55+
| [Kotlin Support with MyBatis3](src/site/markdown/docs/kotlinMyBatis3.md) | Information about the Kotlin extensions and Kotlin DSL when using MyBatis3 as the runtime |
56+
| [Spring Support](src/site/markdown/docs/spring.md) | Information about specialized support for Spring JDBC Templates |
57+
| [Kotlin Support with Spring](src/site/markdown/docs/kotlinSpring.md) | Information about the Kotlin extensions and Kotlin DSL when using Spring JDBC Template as the runtime |
58+
| [Spring Batch Support](src/site/markdown/docs/springBatch.md) | Information about specialized support for Spring Batch using the [MyBatis Spring Integration](https://github.com/mybatis/spring) |
5759

5860
The library test cases provide several complete examples of using the library in various different styles:
5961

60-
| Language | Runtime | Comments | Code Directory |
61-
|---|---|---|---|
62-
| Java | MyBatis3 | Example using Java utility classes for MyBatis in the style of MyBatis Generator | [../examples/simple](src/test/java/examples/simple) |
63-
| Java | MyBatis3 + MyBatis-Spring | Example using MyBatis-Spring integration | [../examples/column/comparison](src/test/java/examples/column/comparison) |
64-
| Java | MyBatis3 + MyBatis-Spring (Spring Batch)| Example using Java utility classes for the MyBatis integration with Spring Batch | [../examples/springbatch](src/test/java/examples/springbatch) |
65-
| Java | Spring JDBC | Example using Java utility classes for Spring JDBC Template | [../examples/spring](src/test/java/examples/spring) |
66-
| Kotlin | MyBatis3 | Example using Kotlin utility classes for MyBatis in the style of MyBatis Generator | [../examples/kotlin/mybatis3/canonical](src/test/kotlin/examples/kotlin/mybatis3/canonical) |
67-
| Kotlin | MyBatis3 + MyBatis-Spring | Example using MyBatis-Spring integration in Kotlin | [../examples/kotlin/mybatis3/column/comparison](src/test/kotlin/examples/kotlin/mybatis3/column/comparison) |
68-
| Kotlin | Spring JDBC | Example using Kotlin utility classes for Spring JDBC Template | [../examples/kotlin/spring/canonical](src/test/kotlin/examples/kotlin/spring/canonical) |
62+
| Language | Runtime | Comments | Code Directory |
63+
|----------|------------------------------------------|------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------|
64+
| Java | MyBatis3 | Example using Java utility classes for MyBatis in the style of MyBatis Generator | [../examples/simple](src/test/java/examples/simple) |
65+
| Java | MyBatis3 + MyBatis-Spring | Example using MyBatis-Spring integration | [../examples/column/comparison](src/test/java/examples/column/comparison) |
66+
| Java | MyBatis3 + MyBatis-Spring (Spring Batch) | Example using Java utility classes for the MyBatis integration with Spring Batch | [../examples/springbatch](src/test/java/examples/springbatch) |
67+
| Java | Spring JDBC | Example using Java utility classes for Spring JDBC Template | [../examples/spring](src/test/java/examples/spring) |
68+
| Kotlin | MyBatis3 | Example using Kotlin utility classes for MyBatis in the style of MyBatis Generator | [../examples/kotlin/mybatis3/canonical](src/test/kotlin/examples/kotlin/mybatis3/canonical) |
69+
| Kotlin | MyBatis3 + MyBatis-Spring | Example using MyBatis-Spring integration in Kotlin | [../examples/kotlin/mybatis3/column/comparison](src/test/kotlin/examples/kotlin/mybatis3/column/comparison) |
70+
| Kotlin | Spring JDBC | Example using Kotlin utility classes for Spring JDBC Template | [../examples/kotlin/spring/canonical](src/test/kotlin/examples/kotlin/spring/canonical) |
6971

7072

7173
## Requirements

0 commit comments

Comments
 (0)