Skip to content

Commit e129c0b

Browse files
committed
change readme
1 parent eb9d37f commit e129c0b

File tree

1 file changed

+7
-4
lines changed
  • mug-guava/src/main/java/com/google/mu/safesql

1 file changed

+7
-4
lines changed

mug-guava/src/main/java/com/google/mu/safesql/README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff 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 = ...;
191191
SafeSql 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

196199
This syntax is:
197200
- ✅ Declarative

0 commit comments

Comments
 (0)