|
77 | 77 | * The main use case though, is to be able to compose subqueries and leaf-level parameters with an |
78 | 78 | * intuitive templating API. |
79 | 79 | * |
| 80 | + * <p>The syntax to create a SQL with JDBC parameters, and potentially with dynamic SQL arguments (such |
| 81 | + * as column names) is as simple and intuitive as the following example: <pre>{@code |
| 82 | + * List<String> groupColumns = ...; |
| 83 | + * SafeSql sql = SafeSql.of( |
| 84 | + * """ |
| 85 | + * SELECT `{group_columns}`, SUM(revenue) AS revenue |
| 86 | + * FROM Sales |
| 87 | + * WHERE sku = {sku} |
| 88 | + * GROUP BY `{group_columns}` |
| 89 | + * """, |
| 90 | + * groupColumns, sku, groupColumns); |
| 91 | + * List<RevenueRecord> results = sql.query(connection, RevenueRecord.class); |
| 92 | + * }</pre> |
| 93 | + * |
| 94 | + * <p>By default, all placeholder values are passed as JDBC parameters, unless quoted by backticks |
| 95 | + * (used by databases like BigQuery, Databricks) or double quotes (used by databases like Oracle, |
| 96 | + * Microsoft SQL Server or PostgreSQL). These are validated and interpreted as identifiers. |
| 97 | + * |
| 98 | + * <p>In the above example, placeholder {@code sku} will be passed as JDBC parameter, |
| 99 | + * whereas the backtick-quoted {@code groupColumns} string list will be validated and then |
| 100 | + * used as identifiers. |
| 101 | + * |
| 102 | + * <p>Except the placeholders, everything outside the curly braces are strictly WYSIWYG |
| 103 | + * (what you see is what you get), so you can copy paste them between the Java code and your SQL |
| 104 | + * console for quick testing and debugging. |
| 105 | + * |
80 | 106 | * <dl><dt><STRONG>The {@code IN} Operator</STRONG></dt></dl> |
81 | 107 | * |
82 | 108 | * A common dynamic SQL use case is to use the {@code IN} SQL operator: |
|
133 | 159 | * <path> |
134 | 160 | * <groupId>com.google.mug</groupId> |
135 | 161 | * <artifactId>mug-errorprone</artifactId> |
136 | | - * <version>8.6</version> |
| 162 | + * <version>8.7</version> |
137 | 163 | * </path> |
138 | 164 | * </annotationProcessorPaths> |
139 | 165 | * </configuration> |
|
0 commit comments