Skip to content

Commit 0f08853

Browse files
committed
README
1 parent aa949c5 commit 0f08853

File tree

1 file changed

+52
-46
lines changed

1 file changed

+52
-46
lines changed

README.md

Lines changed: 52 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,18 @@ The above example will throw an exception if `$since` is not set.
135135

136136
### Type-Safe Placeholders
137137

138-
You can enforce type constraints on placeholders using type suffixes. When a value doesn't match the expected type, an exception is thrown during query rendering.
138+
You can enforce type constraints on placeholders using type suffixes. When a value doesn't match the expected type, an
139+
exception is thrown during query rendering.
139140

140141
#### Scalar Types
141142

142-
| Suffix | Named Syntax | Description |
143-
|--------|--------------|-------------|
144-
| `?i` | `:id!i`, `$id!i` | Integer |
145-
| `?u` | `:age!u`, `$age!u` | Unsigned integer (≥ 0) |
146-
| `?d` | `:score!d`, `$score!d` | Decimal (int, float, or numeric string) |
147-
| `?ud` | `:price!ud`, `$price!ud` | Unsigned decimal (≥ 0, int/float/numeric string) |
148-
| `?s` | `:name!s`, `$name!s` | String |
143+
| Suffix | Named Syntax | Description |
144+
|--------|--------------------------|--------------------------------------------------|
145+
| `?i` | `:id!i`, `$id!i` | Integer |
146+
| `?u` | `:age!u`, `$age!u` | Unsigned integer (≥ 0) |
147+
| `?d` | `:score!d`, `$score!d` | Decimal (int, float, or numeric string) |
148+
| `?ud` | `:price!ud`, `$price!ud` | Unsigned decimal (≥ 0, int/float/numeric string) |
149+
| `?s` | `:name!s`, `$name!s` | String |
149150

150151
```php
151152
// Type validation examples
@@ -162,13 +163,13 @@ $driver->queryAll('SELECT * FROM products WHERE price = ?d', ["abc"]); // Er
162163

163164
#### Array Types (for IN clauses)
164165

165-
| Suffix | Named Syntax | Description |
166-
|--------|--------------|-------------|
167-
| `?ia` | `:ids!ia` | Array of integers |
168-
| `?ua` | `:ids!ua` | Array of unsigned integers |
169-
| `?da` | `:scores!da` | Array of decimals |
166+
| Suffix | Named Syntax | Description |
167+
|--------|---------------|----------------------------|
168+
| `?ia` | `:ids!ia` | Array of integers |
169+
| `?ua` | `:ids!ua` | Array of unsigned integers |
170+
| `?da` | `:scores!da` | Array of decimals |
170171
| `?uda` | `:prices!uda` | Array of unsigned decimals |
171-
| `?sa` | `:names!sa` | Array of strings |
172+
| `?sa` | `:names!sa` | Array of strings |
172173

173174
```php
174175
$driver->queryAll('SELECT * FROM users WHERE id IN :ids!ia', [
@@ -186,14 +187,14 @@ $driver->queryAll('SELECT * FROM users WHERE id IN :ids!ia', [
186187

187188
By default, typed placeholders reject `null` values. Use the `n` prefix to allow nulls:
188189

189-
| Suffix | Named Syntax | Description |
190-
|--------|--------------|-------------|
191-
| `?n` | `:data!n` | Nullable mixed (any type including null) |
192-
| `?ni` | `:id!ni` | Nullable integer |
193-
| `?nu` | `:age!nu` | Nullable unsigned integer |
194-
| `?nd` | `:score!nd` | Nullable decimal |
195-
| `?nud` | `:price!nud` | Nullable unsigned decimal |
196-
| `?ns` | `:name!ns` | Nullable string |
190+
| Suffix | Named Syntax | Description |
191+
|--------|--------------|------------------------------------------|
192+
| `?n` | `:data!n` | Nullable mixed (any type including null) |
193+
| `?ni` | `:id!ni` | Nullable integer |
194+
| `?nu` | `:age!nu` | Nullable unsigned integer |
195+
| `?nd` | `:score!nd` | Nullable decimal |
196+
| `?nud` | `:price!nud` | Nullable unsigned decimal |
197+
| `?ns` | `:name!ns` | Nullable string |
197198

198199
Nullable array types: `?nia`, `?nua`, `?nda`, `?nuda`, `?nsa`
199200

@@ -210,13 +211,13 @@ $driver->queryAll('SELECT * FROM users WHERE id = ?ni', [42]); // OK - render
210211

211212
The nullable flag affects how conditional blocks behave:
212213

213-
| Placeholder | Value | Block Behavior |
214-
|-------------|-------|----------------|
215-
| `:status!ni` (nullable) | absent | Block **skipped** |
216-
| `:status!ni` (nullable) | `null` | Block **rendered** |
217-
| `:status!ni` (nullable) | `5` | Block **rendered** |
218-
| `:status!i` (non-nullable) | `null` | Block **skipped** |
219-
| `:status` (untyped) | `null` | Block **skipped** |
214+
| Placeholder | Value | Block Behavior |
215+
|----------------------------|--------|--------------------|
216+
| `:status!ni` (nullable) | absent | Block **skipped** |
217+
| `:status!ni` (nullable) | `null` | Block **rendered** |
218+
| `:status!ni` (nullable) | `5` | Block **rendered** |
219+
| `:status!i` (non-nullable) | `null` | Block **skipped** |
220+
| `:status` (untyped) | `null` | Block **skipped** |
220221

221222
```php
222223
$sql = 'SELECT * FROM users WHERE 1=1 {{ AND status = :status!ni }}';
@@ -238,14 +239,14 @@ This is useful when you want to explicitly query for `NULL` values vs. omitting
238239

239240
#### Quick Reference Cheat Sheet
240241

241-
| Type | Scalar | Nullable | Array | Nullable Array |
242-
|------|--------|----------|-------|----------------|
243-
| **Any** | `?` | `?n` |||
244-
| **Integer** | `?i` | `?ni` | `?ia` | `?nia` |
245-
| **Unsigned Int** | `?u` | `?nu` | `?ua` | `?nua` |
246-
| **Decimal** | `?d` | `?nd` | `?da` | `?nda` |
247-
| **Unsigned Dec** | `?ud` | `?nud` | `?uda` | `?nuda` |
248-
| **String** | `?s` | `?ns` | `?sa` | `?nsa` |
242+
| Type | Scalar | Nullable | Array | Nullable Array |
243+
|------------------|--------|----------|--------|----------------|
244+
| **Any** | `?` | `?n` | | |
245+
| **Integer** | `?i` | `?ni` | `?ia` | `?nia` |
246+
| **Unsigned Int** | `?u` | `?nu` | `?ua` | `?nua` |
247+
| **Decimal** | `?d` | `?nd` | `?da` | `?nda` |
248+
| **Unsigned Dec** | `?ud` | `?nud` | `?uda` | `?nuda` |
249+
| **String** | `?s` | `?ns` | `?sa` | `?nsa` |
249250

250251
**Named syntax**: Add `!` before suffix: `$id!i`, `:name!s`, `$prices!uda`
251252

@@ -443,7 +444,8 @@ Additional supported methods to be called from inside a closure:
443444

444445
## Retry Policy
445446

446-
The driver supports automatic retry with exponential backoff for transient failures like connection drops, pool exhaustion, and timeouts.
447+
The driver supports automatic retry with exponential backoff for transient failures like connection drops, pool
448+
exhaustion, and timeouts.
447449

448450
```php
449451
$driver = Sqlx\DriverFactory::make([
@@ -465,14 +467,14 @@ $driver = Sqlx\DriverFactory::make([
465467

466468
### Transient vs Non-Transient Errors
467469

468-
| Error Type | Retried? | Examples |
469-
|------------|----------|----------|
470-
| Pool exhausted | ✅ Yes | All connections in use |
471-
| Timeout | ✅ Yes | Connection or query timeout |
472-
| Connection error | ✅ Yes | Connection dropped, network error |
473-
| Query error | ❌ No | Syntax error, constraint violation |
474-
| Transaction error | ❌ No | Deadlock, serialization failure |
475-
| Parse error | ❌ No | Invalid SQL syntax |
470+
| Error Type | Retried? | Examples |
471+
|-------------------|----------|------------------------------------|
472+
| Pool exhausted | ✅ Yes | All connections in use |
473+
| Timeout | ✅ Yes | Connection or query timeout |
474+
| Connection error | ✅ Yes | Connection dropped, network error |
475+
| Query error | ❌ No | Syntax error, constraint violation |
476+
| Transaction error | ❌ No | Deadlock, serialization failure |
477+
| Parse error | ❌ No | Invalid SQL syntax |
476478

477479
---
478480

@@ -760,6 +762,7 @@ $driver->onQuery(null);
760762
```
761763

762764
The callback receives:
765+
763766
- `$sql` – The rendered SQL with placeholders (`SELECT * FROM users WHERE status = $1`)
764767
- `$sqlInline` – The SQL with inlined values for logging (`SELECT * FROM users WHERE status = 'active'`)
765768
- `$durationMs` – Execution time in milliseconds
@@ -786,6 +789,7 @@ $driver->setClientInfo('order-service', [
786789
```
787790

788791
**Database-specific visibility**:
792+
789793
- PostgreSQL: Visible in `pg_stat_activity.application_name`
790794
- MySQL: Stored in session variable `@sqlx_application_name` (queryable via `SELECT @sqlx_application_name`)
791795
- MSSQL: Stored in session context (queryable via `SELECT SESSION_CONTEXT(N'application_name')`)
@@ -808,6 +812,7 @@ $columns = $driver->describeTable('users', 'public');
808812
```
809813

810814
Each column entry contains:
815+
811816
- `name` – Column name (string)
812817
- `type` – Database-specific type (string), e.g., `varchar(255)`, `integer`, `timestamp`
813818
- `nullable` – Whether `NULL` is allowed (bool)
@@ -1104,6 +1109,7 @@ cargo +nightly fuzz run ast_postgres -- -max_total_time=60
11041109
```
11051110

11061111
Available fuzz targets:
1112+
11071113
- `ast_postgres` - PostgreSQL parser
11081114
- `ast_mysql` - MySQL parser
11091115
- `ast_mssql` - MSSQL parser

0 commit comments

Comments
 (0)