You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(oracle): automatic CLOB hydration for msgspec integration (#140)
Adds automatic CLOB-to-string conversion in Oracle adapter to enable seamless msgspec/Pydantic integration. CLOB handles are now read automatically before schema conversion, eliminating the need for `DBMS_LOB.SUBSTR` workarounds.
- Test against actual databases using the docker infrastructure
620
620
- The SQL builder API is experimental and will change significantly
621
621
622
+
## LOB (Large Object) Hydration Pattern
623
+
624
+
### Overview
625
+
626
+
Some database drivers (Oracle, PostgreSQL with large objects) return handle objects for large data types that must be explicitly read before use. SQLSpec provides automatic hydration to ensure typed schemas receive concrete Python values.
Copy file name to clipboardExpand all lines: docs/guides/adapters/oracle.md
+116Lines changed: 116 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -102,6 +102,122 @@ If `use_in_memory=True` but In-Memory is not available/licensed, table creation
102
102
103
103
**Recommendation:** Use `use_in_memory=False` (default) unless you have confirmed licensing and configuration.
104
104
105
+
## CLOB/BLOB Handling
106
+
107
+
Oracle's `oracledb` driver returns LOB (Large Object) handles for CLOB and BLOB columns, which must be read before use. SQLSpec **automatically reads CLOB columns into strings** to provide seamless integration with typed schemas like msgspec and Pydantic.
108
+
109
+
### Automatic CLOB Hydration
110
+
111
+
CLOB values are automatically read and converted to Python strings:
112
+
113
+
```python
114
+
from sqlspec.adapters.oracledb import OracleAsyncConfig
# Had to use DBMS_LOB.SUBSTR, truncating to 4000 chars
201
+
result =await session.execute(
202
+
"SELECT id, DBMS_LOB.SUBSTR(content, 4000) as content FROM articles"
203
+
)
204
+
```
205
+
206
+
**After (automatic, no truncation):**
207
+
208
+
```python
209
+
# CLOB automatically read to full string
210
+
result =await session.execute(
211
+
"SELECT id, content FROM articles"
212
+
)
213
+
```
214
+
215
+
### Performance Considerations
216
+
217
+
-**Memory usage:** Large CLOBs (>100MB) are fully materialized into memory. For multi-GB CLOBs, consider using database-side processing or pagination.
218
+
-**Sync vs Async:** Both sync and async drivers perform automatic CLOB hydration with equivalent performance.
219
+
-**Multiple CLOBs:** All CLOB columns in a result row are hydrated automatically.
220
+
105
221
## Column Name Normalization
106
222
107
223
Oracle returns unquoted identifiers in uppercase (for example `ID`, `PRODUCT_NAME`). When those rows feed into schema libraries that expect snake_case fields, the uppercase keys can trigger validation errors. SQLSpec resolves this automatically through the `enable_lowercase_column_names` driver feature, which is **enabled by default**.
0 commit comments