@@ -20,18 +20,20 @@ For example, a typical search can be coded with a query like this (the following
20
20
similar):
21
21
22
22
``` kotlin
23
- fun search (id_ : String? , firstName_ : String? , lastName_ : String? ) =
23
+ data class SearchParameters (val id : String? , val firstName : String? , val lastName : String? )
24
+
25
+ fun search (searchParameters : SearchParameters ) =
24
26
select(id, firstName, lastName) {
25
27
from(Customer )
26
28
where {
27
29
active isEqualTo true
28
- and { id( isEqualToWhenPresent(id_).map { it?.padStart( 5 , ' 0 ' ) }) }
30
+ and { id isEqualToWhenPresent searchParameters.id }
29
31
and {
30
- firstName(isLikeCaseInsensitiveWhenPresent(firstName_ )
32
+ firstName(isLikeCaseInsensitiveWhenPresent(searchParameters.firstName )
31
33
.map { " %" + it.trim() + " %" })
32
34
}
33
35
and {
34
- lastName(isLikeCaseInsensitiveWhenPresent(lastName_ )
36
+ lastName(isLikeCaseInsensitiveWhenPresent(searchParameters.lastName )
35
37
.map { " %" + it.trim() + " %" })
36
38
}
37
39
}
@@ -44,9 +46,9 @@ This query does quite a lot...
44
46
45
47
1 . It is a search with three search criteria - any combination of search criteria can be used
46
48
2 . Only records with an active status will be returned
47
- 3 . If ` id_ ` is specified, it will be padded to length 5 with '0' at the beginning of the string
48
- 4 . If ` firstName_ ` is specified, it will be used in a case-insensitive search and SQL wildcards will be appended
49
- 5 . If ` lastName_ ` is specified, it will be used in a case-insensitive search and SQL wildcards will be appended
49
+ 3 . If ` id ` is specified, it will be used as a filter
50
+ 4 . If ` firstName ` is specified, it will be used in a case-insensitive search and SQL wildcards will be appended
51
+ 5 . If ` lastName ` is specified, it will be used in a case-insensitive search and SQL wildcards will be appended
50
52
6 . The query results are limited to 500 rows
51
53
52
54
Using the dynamic SQL features of the library eliminates a lot of code that would be required for checking nulls,
0 commit comments