File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed
mug-guava/src/main/java/com/google/mu/safesql Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -184,14 +184,17 @@ The XML-based logic also makes it hard to abstract and reuse subqueries without
184184
185185### ✅ What this looks like in SafeSql:
186186
187- The [ ` SafeSql.optionally() ` ] ( https://google.github.io/mug/apidocs/com/google/mu/safesql/SafeSql.html#optionally(java.lang.String,java.util.Optional) )
188- utility renders an optional template only when the Java ` Optional ` parameter is present.
187+ You use the conditional ` -> ` operator:
189188
190189``` java
190+ Optional<String > keyword = ... ;
191191SafeSql query = SafeSql . of(
192- " SELECT * FROM Users WHERE 1=1 {optionally_and_name }" ,
193- optionally( " AND name LIKE '%{ keyword}%' " , keyword) );
192+ " SELECT * FROM Users WHERE 1=1 {keyword? -> AND name LIKE '%keyword?%' }" ,
193+ keyword);
194194```
195+ The ` keyword? ` placeholder name indicates that it's an ` Optional ` and when present, renders the
196+ snippet to the right of the ` -> ` operator, with all of the ` keyword? ` occurrences parameterized
197+ with the ` keyword ` value.
195198
196199This syntax is:
197200- ✅ Declarative
You can’t perform that action at this time.
0 commit comments