mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-24 13:54:57 +00:00
3.0 KiB
3.0 KiB
SQL Adapter Header Split - 2026-02-07
Objective
Reduce sql_adapter_base.hpp from 157 lines to under 150 LOC while maintaining clear interface.
Solution
Extracted helper declarations and type definitions to separate headers using a three-file split:
File Structure
-
sql_types.hpp (49 lines)
SqlParam- Parameter binding structureSqlRow- Result row structureSqlError- Error codes and message- Note:
Dialectenum remains insql_connection.hpp(already existed)
-
sql_adapter_helpers.hpp (52 lines)
SqlQueryBuilder- SQL query construction (INSERT, SELECT, UPDATE, DELETE)SqlDataConverter- JSON ↔ SQL row conversionSqlUtils- String utilities (snake_case, placeholders, joins)
-
sql_adapter_base.hpp (94 lines) ✅
- Main
SqlAdapterclass interface - Generic CRUD operations (11 methods)
- Bulk operations (3 methods)
- Query operations (3 methods)
- Metadata operations (2 methods)
- Protected methods (schema loading, query execution)
- Main
Changes Made
Extracted to sql_types.hpp
- Moved
SqlParam,SqlRow,SqlErrorstructs - Removed duplicate
Dialectenum (already in sql_connection.hpp)
Extracted to sql_adapter_helpers.hpp
- Created static helper classes for SQL building, data conversion, utilities
- Added
sql_connection.hppinclude forDialectenum
Simplified sql_adapter_base.hpp
- Reduced includes from 14 to 7
- Removed inline implementations from protected methods
- Condensed ConnectionGuard destructor to single line
- Added helper includes:
sql_types.hpp,sql_adapter_helpers.hpp
Results
| Metric | Before | After | Change |
|---|---|---|---|
| sql_adapter_base.hpp LOC | 157 | 94 | -63 (-40%) |
| Target met | ❌ | ✅ | Under 150 LOC |
| Files created | 1 | 3 | +2 helpers |
| Total LOC | 157 | 195 | +38 (from extracted declarations) |
Benefits
- Separation of Concerns: Type definitions, helpers, and main adapter now in separate files
- Reusability: Helper classes can be used by other SQL adapters (future SQLite, MySQL variants)
- Maintainability: Smaller files are easier to navigate and understand
- Compile Time: Can include only needed headers (sql_types.hpp vs full adapter)
- Testing: Helper classes can be unit tested independently
Impact
- ✅ No breaking changes to public API
- ✅ All includes properly updated
- ✅ Dialect enum reused from sql_connection.hpp
- ✅ Clean separation: types, helpers, adapter
Files Modified
src/adapters/sql/sql_adapter_base.hpp- Reduced from 157 to 94 linessrc/adapters/sql/sql_types.hpp- NEW (49 lines)src/adapters/sql/sql_adapter_helpers.hpp- NEW (52 lines)
Implementation Pattern
This split follows the pattern:
- Types layer - Basic data structures (sql_types.hpp)
- Helpers layer - Static utility functions (sql_adapter_helpers.hpp)
- Adapter layer - Main business logic (sql_adapter_base.hpp)
Can be applied to other large headers in the codebase.