Skip to content

Commit cb58a74

Browse files
committed
docs: improved readability
1 parent 06a7522 commit cb58a74

11 files changed

Lines changed: 346 additions & 46 deletions

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
A lightweight, fluent Java library for building parameterized SQL queries and filtering in-memory data, no runtime dependencies required.
88

9+
910
## Features
1011

1112
- Fluent, readable builder API for SELECT, INSERT, UPDATE, DELETE, and CREATE TABLE
@@ -14,6 +15,7 @@ A lightweight, fluent Java library for building parameterized SQL queries and fi
1415
- Subquery support: `WHERE col IN (SELECT ...)`, `WHERE EXISTS (SELECT ...)`, `WHERE NOT EXISTS`, derived-table `FROM (SELECT ...) AS alias`, JOIN subqueries, and scalar `(SELECT ...) AS alias` in SELECT
1516
- Column selection, `DISTINCT`, `GROUP BY`, `ORDER BY`, `LIMIT`, and `OFFSET`
1617
- SQL dialect support: Standard, MySQL, SQLite
18+
- **Global and per-query configuration of defaults (e.g., dialect, columns, limit, LIKE wrapping) via `QueryBuilderDefaults`**
1719
- In-memory filtering via `QueryableStorage`
1820
- Zero runtime dependencies, pure Java 21+
1921

@@ -391,6 +393,48 @@ new SelectBuilder()
391393
.build(); // → SqlResult
392394
```
393395

396+
397+
## Global and Per-Query Configuration
398+
399+
You can preset the default SQL dialect, default columns, limit, offset, and LIKE wrapping for all queries using `QueryBuilderDefaults`. This is useful for enforcing a project-wide dialect (e.g., always use SQLite) or customizing builder defaults.
400+
401+
### Set SQLite as the default dialect for all queries
402+
403+
```java
404+
import com.github.ezframework.javaquerybuilder.query.QueryBuilderDefaults;
405+
import com.github.ezframework.javaquerybuilder.query.sql.SqlDialect;
406+
407+
// Set at application startup:
408+
QueryBuilderDefaults.setGlobal(
409+
QueryBuilderDefaults.builder()
410+
.dialect(SqlDialect.SQLITE)
411+
.build()
412+
);
413+
414+
// All new QueryBuilder, SelectBuilder, and DeleteBuilder instances will use SQLite quoting by default:
415+
SqlResult result = new QueryBuilder()
416+
.select("id", "name")
417+
.from("users")
418+
.buildSql();
419+
// → SELECT id, name FROM "users"
420+
```
421+
422+
### Override per query
423+
424+
You can override the defaults for a single query using `.withDefaults()`:
425+
426+
```java
427+
SqlResult result = new QueryBuilder()
428+
.withDefaults(QueryBuilderDefaults.builder(QueryBuilderDefaults.global())
429+
.dialect(SqlDialect.MYSQL)
430+
.build())
431+
.from("users")
432+
.buildSql();
433+
// → SELECT * FROM `users`
434+
```
435+
436+
See the Javadoc for [`QueryBuilderDefaults`](src/main/java/com/github/ezframework/javaquerybuilder/query/QueryBuilderDefaults.java) for all configurable options.
437+
394438
## SQL Dialects
395439

396440
By default, `buildSql(table)` uses `SqlDialect.STANDARD` (no identifier quoting). Pass a second argument to use a different dialect:

docs/api-reference.md

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: API Reference
3-
nav_order: 10
3+
nav_order: 11
44
description: "Complete public method tables for every class and interface in JavaQueryBuilder"
55
---
66

@@ -70,8 +70,10 @@ Main entry point for SELECT queries and static gateway to DML builders.
7070
| `offset(int n)` | `QueryBuilder` | Set `OFFSET` |
7171
| `build()` | `Query` | Build a `Query` object (no SQL rendered yet) |
7272
| `buildSql()` | `SqlResult` | Render SELECT using table set via `from()`, standard dialect |
73+
| `buildSql(SqlDialect)` | `SqlResult` | Render SELECT using table set via `from()`, specified dialect |
7374
| `buildSql(String table)` | `SqlResult` | Render SELECT for explicit `table`, standard dialect |
7475
| `buildSql(String table, SqlDialect)` | `SqlResult` | Render SELECT for explicit `table` and dialect |
76+
| `withDefaults(QueryBuilderDefaults)` | `QueryBuilder` | Set per-instance configuration defaults; throws `NullPointerException` if `null` |
7577

7678
---
7779

@@ -91,6 +93,8 @@ Lower-level SELECT builder that produces `SqlResult` directly (no `Query` interm
9193
| `orderBy(String col, boolean asc)` | `SelectBuilder` | Add `ORDER BY` |
9294
| `limit(int n)` | `SelectBuilder` | Set `LIMIT` |
9395
| `offset(int n)` | `SelectBuilder` | Set `OFFSET` |
96+
| `withDefaults(QueryBuilderDefaults)` | `SelectBuilder` | Set per-instance configuration defaults; throws `NullPointerException` if `null` |
97+
| `build()` | `SqlResult` | Render SELECT using defaults dialect |
9498
| `build(SqlDialect)` | `SqlResult` | Render SELECT with given dialect |
9599

96100
---
@@ -134,6 +138,7 @@ Lower-level SELECT builder that produces `SqlResult` directly (no `Query` interm
134138
| `whereIn(col, List<?>)` | `DeleteBuilder` | `WHERE col IN (...)` (AND); throws `IllegalArgumentException` if list is null/empty |
135139
| `whereNotIn(col, List<?>)` | `DeleteBuilder` | `WHERE col NOT IN (...)` (AND); throws `IllegalArgumentException` if list is null/empty |
136140
| `whereBetween(col, from, to)` | `DeleteBuilder` | `WHERE col BETWEEN ? AND ?` (AND) |
141+
| `withDefaults(QueryBuilderDefaults)` | `DeleteBuilder` | Set per-instance configuration defaults; throws `NullPointerException` if `null` |
137142
| `build()` | `SqlResult` | Render with standard dialect |
138143
| `build(SqlDialect)` | `SqlResult` | Render with specified dialect |
139144

@@ -242,7 +247,7 @@ getters and setters; setters are used exclusively by the builders.
242247
|--------|-------------|
243248
| `JoinClause(Type, String table, String on)` | Plain-table join |
244249
| `JoinClause(Type, Query subquery, String alias, String on)` | Subquery (derived-table) join |
245-
| `getType()` | `JoinClause.Type``INNER`, `LEFT`, `RIGHT`, or `CROSS` |
250+
| `getType()` | `JoinClause.Type`: `INNER`, `LEFT`, `RIGHT`, or `CROSS` | Join type |
246251
| `getTable()` | Table name for plain-table join; `null` for subquery join |
247252
| `getSubquery()` | Subquery for derived-table join; `null` for plain-table join |
248253
| `getAlias()` | Alias for derived-table join |
@@ -279,9 +284,9 @@ public interface QueryableStorage {
279284

280285
| Member | Description |
281286
|--------|-------------|
282-
| `STANDARD` | ANSI SQL no identifier quoting |
283-
| `MYSQL` | MySQL back-tick quoting; DELETE LIMIT supported |
284-
| `SQLITE` | SQLite double-quote quoting; DELETE LIMIT supported |
287+
| `STANDARD` | ANSI SQL (no identifier quoting) |
288+
| `MYSQL` | MySQL: back-tick quoting; DELETE LIMIT supported |
289+
| `SQLITE` | SQLite: double-quote quoting; DELETE LIMIT supported |
285290
| `render(Query)` | Render a SELECT query to `SqlResult` |
286291
| `renderDelete(Query)` | Render a DELETE query to `SqlResult` |
287292

@@ -296,6 +301,49 @@ public interface QueryableStorage {
296301

297302
---
298303

304+
## configuration
305+
306+
### `QueryBuilderDefaults`
307+
308+
Immutable configuration object. See [Configuration](configuration) for a full
309+
usage guide.
310+
311+
**Static methods**
312+
313+
| Method | Returns | Description |
314+
|--------|---------|-------------|
315+
| `global()` | `QueryBuilderDefaults` | Current JVM-wide defaults instance |
316+
| `setGlobal(defaults)` | `void` | Replace the JVM-wide defaults; throws `NullPointerException` if `null` |
317+
| `builder()` | `Builder` | New builder pre-filled with canonical defaults |
318+
| `builder(source)` | `Builder` | New builder copied from `source`; throws `NullPointerException` if `null` |
319+
320+
**Instance getters**
321+
322+
| Method | Returns | Description |
323+
|--------|---------|-------------|
324+
| `getDialect()` | `SqlDialect` | Configured SQL dialect |
325+
| `getDefaultColumns()` | `String` | Default SELECT column expression |
326+
| `getDefaultLimit()` | `int` | Default LIMIT; `-1` means none |
327+
| `getDefaultOffset()` | `int` | Default OFFSET; `-1` means none |
328+
| `getLikePrefix()` | `String` | Prefix for LIKE values |
329+
| `getLikeSuffix()` | `String` | Suffix for LIKE values |
330+
331+
---
332+
333+
### `QueryBuilderDefaults.Builder`
334+
335+
| Method | Returns | Description |
336+
|--------|---------|-------------|
337+
| `dialect(SqlDialect)` | `Builder` | Set dialect; throws `NullPointerException` if `null` |
338+
| `defaultColumns(String)` | `Builder` | Set default SELECT columns; throws `NullPointerException` if `null` |
339+
| `defaultLimit(int)` | `Builder` | Set default LIMIT; pass `-1` to disable |
340+
| `defaultOffset(int)` | `Builder` | Set default OFFSET; pass `-1` to disable |
341+
| `likePrefix(String)` | `Builder` | Set LIKE prefix; throws `NullPointerException` if `null` |
342+
| `likeSuffix(String)` | `Builder` | Set LIKE suffix; throws `NullPointerException` if `null` |
343+
| `build()` | `QueryBuilderDefaults` | Build the immutable configuration object |
344+
345+
---
346+
299347
## exception
300348

301349
### `QueryBuilderException`

docs/conditions.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ description: "Operators, Condition, ConditionEntry, Connector AND/OR, and the or
1717

1818
## Overview
1919

20-
Every `where*` call on a builder creates a `ConditionEntry` — a triple of:
20+
Every `where*` call on a builder creates a `ConditionEntry` with three properties:
2121

2222
- a **column name** (or `null` for EXISTS subquery conditions)
2323
- a **`Condition`** (operator + value)
@@ -84,7 +84,7 @@ constant and the SQL it generates.
8484

8585
## AND vs OR connector
8686

87-
### Default AND
87+
### Default behavior (AND)
8888

8989
All `where*` methods use `AND`:
9090

@@ -96,7 +96,7 @@ new QueryBuilder()
9696
// → WHERE role = ? AND active = ?
9797
```
9898

99-
### OR — use the `orWhere*` variant
99+
### OR conditions
100100

101101
```java
102102
new QueryBuilder()

0 commit comments

Comments
 (0)