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
feat(config): simplify add_config return type (#278)
- Update the configuration registry to use instance IDs as keys, allowing multiple configurations of the same adapter type. - Modify the `add_config` method to return the configuration instance directly and ensure all relevant methods accept configuration instances.
- Introduce validation for unregistered configurations and add a new method to retrieve configurations by type.
- Remove deprecated methods and update tests accordingly.
- Database client library requires specific encoding for binary data
261
263
- Need transparent conversion between Python bytes and database format
262
264
- Want to centralize encoding/decoding logic for reuse
263
265
264
266
**Key principles**:
267
+
265
268
- Centralize conversion functions in `_type_handlers.py`
266
269
- Handle None/NULL values explicitly
267
270
- Support both raw and encoded formats on read (graceful handling)
268
271
- Use in `coerce_params_for_database()` and type converter
269
272
270
273
**Example**: Spanner requires base64-encoded bytes for `param_types.BYTES` parameters, but you work with raw Python bytes in application code.
271
274
275
+
### Instance-Based Config Registry Pattern
276
+
277
+
SQLSpec uses config instances as handles for database connections. The registry keys by `id(config)` instead of `type(config)` to support multiple databases of the same adapter type.
278
+
279
+
```python
280
+
from sqlspec import SQLSpec
281
+
from sqlspec.adapters.asyncpg import AsyncpgConfig
282
+
283
+
manager = SQLSpec()
284
+
285
+
# Config instance IS the handle - add_config returns same instance
0 commit comments