Skip to content

Commit 1b7cd1d

Browse files
committed
SafeSql javadoc refinement
1 parent ed7bb8b commit 1b7cd1d

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,32 @@
7777
* The main use case though, is to be able to compose subqueries and leaf-level parameters with an
7878
* intuitive templating API.
7979
*
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+
*
80106
* <dl><dt><STRONG>The {@code IN} Operator</STRONG></dt></dl>
81107
*
82108
* A common dynamic SQL use case is to use the {@code IN} SQL operator:
@@ -133,7 +159,7 @@
133159
* <path>
134160
* <groupId>com.google.mug</groupId>
135161
* <artifactId>mug-errorprone</artifactId>
136-
* <version>8.6</version>
162+
* <version>8.7</version>
137163
* </path>
138164
* </annotationProcessorPaths>
139165
* </configuration>

0 commit comments

Comments
 (0)