How nilportugues/php-sql-query-builder works
High-Level Components
┌─────────────────────────────────────────────────────┐
• Client Application │
• ┘
• ↓
┌─────────────────────────────────────────────────────┐
• Query Builder Core │
• ┬─────────────────┬────────────-┤
• Builder │ Manipulation │ Syntax │
• ┴─────────────────┴────────────-┘
• ↓
┌─────────────────────────────────────────────────────┐
• Database System │
• ┘
Core Components Breakdown
Builder Component
┌────────────────────────────────┐
• BuilderInterface │
• ┤
• GenericBuilder │
• MySqlBuilder │
• BuilderException │
• ┘
Manipulation Component
┌────────────────────────────────┐
• QueryInterface │
• ┤
• AbstractBaseQuery │
• Select/Insert/Update/Delete │
• Union/Intersect/Minus │
• QueryFactory │
• ┘
Syntax Component
┌────────────────────────────────┐
• QueryPartInterface │
• ┤
• Column/Table/Where │
• OrderBy │
• SyntaxFactory │
• ┘
Builder Syntax Writers
┌─────────────────────────────┐
• AbstractBaseWriter │
• ┬───────────────┘
• ↓
┌─────────────────────────────┐
• AbstractSetWriter │
• ┬───────────────┘
• ↓
┌─────────────────────────────┐
• Specific Writers │
• ┤
• SelectWriter │
• InsertWriter │
• UpdateWriter │
• DeleteWriter │
• WhereWriter │
• etc... │
• ┘
Data Flow Representation
Client → Builder → QueryFactory → Query Objects → Writers → SQL String
• ↓
• Values Array
Important Design Elements to Highlight
• Blue: Core interfaces
• Green: Concrete implementations
• Yellow: Factories
• Red: Exceptions
• Use different line styles:
Additional Notes
• Version information
• Supported database systems (Generic SQL-2003 and MySQL)
• Where query binding happens
• Separation between query building and execution
Implementation Details to Note
• The Builder pattern implementation
• Factory pattern usage
• Interface segregation
• Composition over inheritance
• Chain of responsibility in query building
Remember to include notes about:
• The stateless nature of the query builder
• The separation between query building and execution
• The value binding system
• The extensibility points for new database dialects
This will provide a complete picture of how the SQL Query Builder works while maintaining the right level of abstraction for a principal software engineer to understand the system's architecture.