Skip to content

Commit 030fc0d

Browse files
committed
docs: update documentation for PostgreSQL support (1.1.0)
- sql-dialects.md: add POSTGRESQL to overview table, usage example, dialect matrix, AbstractSqlDialect section, and interface table - conditions.md: add ILIKE/NOT_ILIKE to Operator table and builder method reference table - dml-builders.md: add RETURNING clause section with DELETE/INSERT/UPDATE examples; add returning() to InsertBuilder, UpdateBuilder, DeleteBuilder method reference tables - index.md: bump badges and version snippet to 1.1.0, update operator count (16→18), dialect list (Three→Four, add POSTGRESQL), docs table - installation.md: bump Maven, Gradle, and GitHub Packages version snippets from 1.0.4 to 1.1.0
1 parent e93ddf0 commit 030fc0d

5 files changed

Lines changed: 102 additions & 34 deletions

File tree

docs/conditions.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ conditions use `AND` by default; call the `orWhere*` variant to use `OR`.
5050
| `BETWEEN` | `col BETWEEN ? AND ?` | Inclusive range; value is a two-element `List<?>` |
5151
| `EXISTS_SUBQUERY` | `EXISTS (SELECT ...)` | Value is a `Query`; column is `null` |
5252
| `NOT_EXISTS_SUBQUERY` | `NOT EXISTS (SELECT ...)` | Value is a `Query`; column is `null` |
53+
| `ILIKE` | `col ILIKE ?` | Case-insensitive substring match — **PostgreSQL only** |
54+
| `NOT_ILIKE` | `col NOT ILIKE ?` | Negated case-insensitive match — **PostgreSQL only** |
5355

5456
---
5557

@@ -69,6 +71,8 @@ constant and the SQL it generates.
6971
| `whereLessThanOrEquals(col, val)` | `LTE` | `col <= ?` |
7072
| `whereLike(col, val)` | `LIKE` | `col LIKE ?` |
7173
| `whereNotLike(col, val)` | `NOT_LIKE` | `col NOT LIKE ?` |
74+
| `whereILike(col, val)` | `ILIKE` | `col ILIKE ?` (PostgreSQL only) |
75+
| `orWhereILike(col, val)` | `ILIKE` | `OR col ILIKE ?` (PostgreSQL only) |
7276
| `whereNull(col)` | `IS_NULL` | `col IS NULL` |
7377
| `whereNotNull(col)` | `IS_NOT_NULL` | `col IS NOT NULL` |
7478
| `whereExists(col)` | `EXISTS` | `col IS NOT NULL` |

docs/dml-builders.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ SqlResult result = QueryBuilder.insertInto("users")
6161
|--------|---------|-------------|
6262
| `into(String table)` | `InsertBuilder` | Set target table (also available via factory) |
6363
| `value(String col, Object val)` | `InsertBuilder` | Add a column/value pair |
64+
| `returning(String... cols)` | `InsertBuilder` | Append `RETURNING col1, col2, ...` (PostgreSQL only) |
6465
| `build()` | `SqlResult` | Render with standard dialect |
6566
| `build(SqlDialect dialect)` | `SqlResult` | Render with specified dialect |
6667

@@ -111,6 +112,7 @@ SqlResult result = QueryBuilder.update("users")
111112
| `whereEquals(String col, Object val)` | `UpdateBuilder` | `WHERE col = ?` (AND) |
112113
| `orWhereEquals(String col, Object val)` | `UpdateBuilder` | `WHERE col = ?` (OR) |
113114
| `whereGreaterThanOrEquals(String col, int val)` | `UpdateBuilder` | `WHERE col >= ?` (AND) |
115+
| `returning(String... cols)` | `UpdateBuilder` | Append `RETURNING col1, col2, ...` (PostgreSQL only) |
114116
| `build()` | `SqlResult` | Render with standard dialect |
115117
| `build(SqlDialect dialect)` | `SqlResult` | Render with specified dialect |
116118

@@ -186,11 +188,65 @@ SqlResult result = SqlDialect.MYSQL.renderDelete(q);
186188
| `whereIn(col, List<?>)` | `DeleteBuilder` | `WHERE col IN (...)` (AND) |
187189
| `whereNotIn(col, List<?>)` | `DeleteBuilder` | `WHERE col NOT IN (...)` (AND) |
188190
| `whereBetween(col, from, to)` | `DeleteBuilder` | `WHERE col BETWEEN ? AND ?` (AND) |
191+
| `returning(String... cols)` | `DeleteBuilder` | Append `RETURNING col1, col2, ...` (PostgreSQL only; use with `SqlDialect.POSTGRESQL`) |
189192
| `build()` | `SqlResult` | Render with standard dialect |
190193
| `build(SqlDialect dialect)` | `SqlResult` | Render with specified dialect |
191194

192195
---
193196

197+
## RETURNING clause (PostgreSQL)
198+
{: #returning-clause-postgresql }
199+
200+
All three DML builders support a `RETURNING` clause for PostgreSQL, which
201+
lets the database return column values from affected rows in a single round-trip.
202+
203+
### DELETE … RETURNING
204+
205+
`RETURNING` on `DELETE` is rendered by the dialect — it is only appended when
206+
`SqlDialect.POSTGRESQL` (or another dialect that overrides `supportsReturning()`)
207+
is active.
208+
209+
```java
210+
SqlResult result = QueryBuilder.deleteFrom("users")
211+
.whereEquals("id", 99)
212+
.returning("id", "email")
213+
.build(SqlDialect.POSTGRESQL);
214+
215+
// → DELETE FROM "users" WHERE "id" = ? RETURNING id, email
216+
// Parameters: [99]
217+
```
218+
219+
### INSERT … RETURNING
220+
221+
`RETURNING` on `INSERT` is appended inline regardless of dialect — the caller
222+
is responsible for using a PostgreSQL connection.
223+
224+
```java
225+
SqlResult result = QueryBuilder.insertInto("users")
226+
.value("name", "Alice")
227+
.value("email", "alice@example.com")
228+
.returning("id", "created_at")
229+
.build();
230+
231+
// → INSERT INTO users (name, email) VALUES (?, ?) RETURNING id, created_at
232+
// Parameters: ["Alice", "alice@example.com"]
233+
```
234+
235+
### UPDATE … RETURNING
236+
237+
```java
238+
SqlResult result = QueryBuilder.update("users")
239+
.set("status", "active")
240+
.whereEquals("id", 7)
241+
.returning("id", "updated_at")
242+
.build();
243+
244+
// → UPDATE users SET status = ? WHERE id = ? RETURNING id, updated_at
245+
// Parameters: ["active", 7]
246+
```
247+
248+
---
249+
194250
## CreateBuilder
195251

196252
### Basic CREATE TABLE

docs/index.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ permalink: /
99
# JavaQueryBuilder
1010

1111
[![JitPack](https://jitpack.io/v/EzFramework/JavaQueryBuilder.svg)](https://jitpack.io/#EzFramework/JavaQueryBuilder)
12-
[![GitHub Packages](https://img.shields.io/badge/GitHub_Packages-1.0.4-blue?logo=github)](https://github.com/EzFramework/JavaQueryBuilder/packages)
12+
[![GitHub Packages](https://img.shields.io/badge/GitHub_Packages-1.1.0-blue?logo=github)](https://github.com/EzFramework/JavaQueryBuilder/packages)
1313

1414
**JavaQueryBuilder** is a lightweight, fluent Java library for building
1515
parameterized SQL queries and filtering in-memory data.
@@ -24,12 +24,12 @@ No runtime dependencies required.
2424
- **DML builders**: `InsertBuilder`, `UpdateBuilder`, `DeleteBuilder`, `CreateBuilder`
2525
- **Parameterized-only**: user values always go through `?` bind parameters; SQL injection
2626
is structurally impossible
27-
- **16 operators**: equality, comparison, `LIKE`, `NULL` checks, `IN`, `BETWEEN`,
27+
- **18 operators**: equality, comparison, `LIKE`, `ILIKE` (PostgreSQL), `NULL` checks, `IN`, `BETWEEN`,
2828
`EXISTS`, and subquery operators
2929
- **Subquery support**: `WHERE col IN (SELECT ...)`, `WHERE EXISTS (SELECT ...)`,
3030
`WHERE NOT EXISTS (SELECT ...)`, scalar `WHERE col = (SELECT ...)`,
3131
FROM-derived table, JOIN subquery, and scalar `SELECT` items
32-
- **Three SQL dialects**: `STANDARD` (ANSI), `MYSQL` (back-tick quoting), `SQLITE` (double-quote)
32+
- **Four SQL dialects**: `STANDARD` (ANSI), `MYSQL` (back-tick quoting), `SQLITE` (double-quote), `POSTGRESQL` (double-quote + `ILIKE` + `RETURNING`)
3333
- **Global and per-query configuration** via `QueryBuilderDefaults`: preset dialect, default
3434
columns, limit, offset, and LIKE wrapping once at application startup
3535
- **In-memory filtering**: `QueryableStorage` functional interface applies the same `Query`
@@ -53,7 +53,7 @@ No runtime dependencies required.
5353
<dependency>
5454
<groupId>com.github.EzFramework</groupId>
5555
<artifactId>JavaQueryBuilder</artifactId>
56-
<version>1.0.4</version>
56+
<version>1.1.0</version>
5757
</dependency>
5858
```
5959

@@ -104,9 +104,9 @@ SqlResult update = QueryBuilder.update("users")
104104
| [Installation](installation) | Maven, Gradle, JitPack, GitHub Packages |
105105
| [Query Builder](query-builder) | SELECT: `from`, `select`, `where*`, `orderBy`, `build` |
106106
| [DML Builders](dml-builders) | `InsertBuilder`, `UpdateBuilder`, `DeleteBuilder`, `CreateBuilder` |
107-
| [Conditions](conditions) | All 16 operators, `Condition`, `ConditionEntry`, `Connector` |
107+
| [Conditions](conditions) | All 18 operators, `Condition`, `ConditionEntry`, `Connector` |
108108
| [Subqueries](subqueries) | All six subquery variants |
109-
| [SQL Dialects](sql-dialects) | `STANDARD`, `MYSQL`, `SQLITE`, `SqlResult`, dialect matrix |
109+
| [SQL Dialects](sql-dialects) | `STANDARD`, `MYSQL`, `SQLITE`, `POSTGRESQL`, `SqlResult`, dialect matrix |
110110
| [Configuration](configuration) | `QueryBuilderDefaults`: global and per-query dialect, columns, limit, LIKE wrapping |
111111
| [In-Memory Filtering](in-memory) | `QueryableStorage`: filter collections without a database |
112112
| [Exceptions](exceptions) | Error hierarchy and handling patterns |

docs/installation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ your classpath.
4646
<dependency>
4747
<groupId>com.github.EzFramework</groupId>
4848
<artifactId>JavaQueryBuilder</artifactId>
49-
<version>1.0.4</version>
49+
<version>1.1.0</version>
5050
</dependency>
5151
```
5252

@@ -66,7 +66,7 @@ repositories {
6666

6767
```kotlin
6868
dependencies {
69-
implementation("com.github.EzFramework:JavaQueryBuilder:1.0.4")
69+
implementation("com.github.EzFramework:JavaQueryBuilder:1.1.0")
7070
}
7171
```
7272

@@ -102,7 +102,7 @@ authenticate with a personal access token that has `read:packages` scope.
102102
<dependency>
103103
<groupId>com.github.EzFramework</groupId>
104104
<artifactId>java-query-builder</artifactId>
105-
<version>1.0.4</version>
105+
<version>1.1.0</version>
106106
</dependency>
107107
```
108108

docs/sql-dialects.md

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ description: "SqlDialect, SqlResult, AbstractSqlDialect, and the dialect matrix"
2121
parameterized `SqlResult`. Three built-in dialects are provided as constants
2222
on the interface:
2323

24-
| Constant | Identifier quoting | DELETE LIMIT |
25-
|----------|--------------------|--------------|
26-
| `SqlDialect.STANDARD` | None (ANSI) | Not supported |
27-
| `SqlDialect.MYSQL` | Back-tick `` ` `` | Supported |
28-
| `SqlDialect.SQLITE` | Double-quote `"` | Supported |
24+
| Constant | Identifier quoting | DELETE LIMIT | ILIKE | RETURNING |
25+
|----------|--------------------|--------------| ------|----------|
26+
| `SqlDialect.STANDARD` | None (ANSI) | Not supported | No | No |
27+
| `SqlDialect.MYSQL` | Back-tick `` ` `` | Supported | No | No |
28+
| `SqlDialect.SQLITE` | Double-quote `"` | Supported | No | No |
29+
| `SqlDialect.POSTGRESQL` | Double-quote `"` | Not supported | Yes | Yes (DELETE) |
2930

3031
---
3132

@@ -54,6 +55,14 @@ SqlResult r3 = new QueryBuilder()
5455
.whereEquals("id", 1)
5556
.buildSql(SqlDialect.SQLITE);
5657
// → SELECT * FROM "users" WHERE "id" = ?
58+
59+
// PostgreSQL: double-quoted identifiers + ILIKE support
60+
SqlResult r4 = new QueryBuilder()
61+
.from("users")
62+
.whereILike("email", "alice")
63+
.buildSql(SqlDialect.POSTGRESQL);
64+
// → SELECT * FROM "users" WHERE "email" ILIKE ?
65+
// Parameters: ["%alice%"]
5766
```
5867

5968
---
@@ -87,7 +96,8 @@ List<Object> params = result.getParameters();
8796
## Rendering DELETE statements
8897

8998
Use `renderDelete(Query)` on a dialect instance to produce `DELETE FROM ...`
90-
statements. This respects the `LIMIT` clause on dialects that support it.
99+
statements. This respects the `LIMIT` clause on dialects that support it and
100+
the `RETURNING` clause on PostgreSQL.
91101

92102
```java
93103
Query q = new QueryBuilder()
@@ -109,25 +119,30 @@ SqlResult sq = SqlDialect.SQLITE.renderDelete(q);
109119
// → DELETE FROM "sessions" WHERE "expired" = ? LIMIT 500
110120
```
111121

122+
For PostgreSQL `RETURNING`, use `DeleteBuilder.returning()` — see [DML Builders](dml-builders#returning-clause-postgresql).
123+
112124
---
113125

114126
## Dialect matrix
115127

116128
The same `Query` produces different SQL across dialects due to identifier quoting:
117129

118-
| Feature | STANDARD | MYSQL | SQLITE |
119-
|---------|----------|-------|--------|
120-
| Table quoting | `users` | `` `users` `` | `"users"` |
121-
| Column quoting | `id` | `` `id` `` | `"id"` |
122-
| DELETE LIMIT | No | Yes | Yes |
123-
| Parameter syntax | `?` | `?` | `?` |
130+
| Feature | STANDARD | MYSQL | SQLITE | POSTGRESQL |
131+
|---------|----------|-------|--------|------------|
132+
| Table quoting | `users` | `` `users` `` | `"users"` | `"users"` |
133+
| Column quoting | `id` | `` `id` `` | `"id"` | `"id"` |
134+
| DELETE LIMIT | No | Yes | Yes | No |
135+
| ILIKE / NOT ILIKE | No | No | No | Yes |
136+
| RETURNING on DELETE | No | No | No | Yes |
137+
| Parameter syntax | `?` | `?` | `?` | `?` |
124138

125139
---
126140

127141
## AbstractSqlDialect
128142

129143
`AbstractSqlDialect` implements the shared rendering logic for SELECT and DELETE
130-
queries. It is the base class for both `MySqlDialect` and `SqliteDialect`.
144+
queries. It is the base class for `MySqlDialect`, `SqliteDialect`, and
145+
`PostgreSqlDialect`.
131146

132147
**Subquery parameter ordering**: parameters are collected depth-first in this
133148
order:
@@ -137,17 +152,9 @@ order:
137152
3. JOIN subquery parameters (left to right)
138153
4. WHERE condition subquery parameters (top to bottom)
139154

140-
To create a custom dialect (e.g. PostgreSQL with `"..."` quoting), extend
141-
`AbstractSqlDialect` and override `quoteIdentifier`:
142-
143-
```java
144-
public class PostgreSqlDialect extends AbstractSqlDialect {
145-
@Override
146-
protected String quoteIdentifier(String name) {
147-
return '"' + name + '"';
148-
}
149-
}
150-
```
155+
To create a fully custom dialect, extend `AbstractSqlDialect` and override any
156+
combination of `quoteIdentifier`, `supportsDeleteLimit`, `supportsReturning`,
157+
and `appendConditionFragment`.
151158

152159
---
153160

@@ -158,5 +165,6 @@ public class PostgreSqlDialect extends AbstractSqlDialect {
158165
| `SqlDialect.STANDARD` | ANSI SQL constant instance |
159166
| `SqlDialect.MYSQL` | MySQL dialect constant instance |
160167
| `SqlDialect.SQLITE` | SQLite dialect constant instance |
168+
| `SqlDialect.POSTGRESQL` | PostgreSQL dialect constant instance |
161169
| `render(Query)` | Render a `SELECT` query to `SqlResult` |
162-
| `renderDelete(Query)` | Render a `DELETE` query to `SqlResult`; observes `LIMIT` on supporting dialects |
170+
| `renderDelete(Query)` | Render a `DELETE` query to `SqlResult`; observes `LIMIT` and `RETURNING` on supporting dialects |

0 commit comments

Comments
 (0)