Skip to content

Commit 7ee6ed8

Browse files
committed
feat: implement dialect-specific DDL query builders
- Add dialect-specific DDL query builders for MySQL, PostgreSQL, MSSQL, SQLite, and MariaDB - Implement MySQL-specific types: enum, set, tinyInteger, mediumInteger, tinyText, mediumText, longText, binary, varbinary, blob types, geometry types, year - Implement PostgreSQL-specific types: uuid, jsonb, serial, bigSerial, inet, cidr, macaddr, tsvector, tsquery, bytea, money, interval, array types, geometric types - Implement MSSQL-specific types: uniqueidentifier, nvarchar, nchar, ntext, money, smallMoney, datetime2, smallDatetime, datetimeOffset, time, binary, varbinary, image, real, xml, geography, geometry, hierarchyid, sqlVariant - Implement SQLite-specific type mappings for all column types - Replace deprecated NTEXT with NVARCHAR(MAX) in MSSQL dialect for better compatibility - Override string() and text() methods in MSSQL to use NVARCHAR for Unicode support - Add DialectInterface::getDdlQueryBuilder() method - Update PdoDb::schema() to return dialect-specific builder - Add comprehensive tests for each dialect's specific types - Add migration test to verify dialect-specific builders are used - Add example demonstrating dialect-specific types with proper MSSQL binary data handling using CONVERT - Update documentation with dialect-specific schema guide - Update README files with new functionality
1 parent 72f1b45 commit 7ee6ed8

25 files changed

+3018
-7
lines changed

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Built on top of PDO with **zero external dependencies**, it offers:
5959
- **UPDATE/DELETE with JOIN** - Update and delete operations with JOIN clauses (MySQL/MariaDB/PostgreSQL/MSSQL)
6060
- **MERGE Statements** - INSERT/UPDATE/DELETE based on match conditions (PostgreSQL/MSSQL native, MySQL/SQLite emulated)
6161
- **Schema Introspection** - Query indexes, foreign keys, and constraints programmatically
62-
- **DDL Query Builder** - Production-ready fluent API for creating, altering, and managing database schema (tables, columns, indexes, foreign keys, constraints) with Yii2-style methods, partial indexes, fulltext/spatial indexes, and cross-dialectal support
62+
- **DDL Query Builder** - Production-ready fluent API for creating, altering, and managing database schema (tables, columns, indexes, foreign keys, constraints) with Yii2-style methods, partial indexes, fulltext/spatial indexes, cross-dialectal support, and **dialect-specific types** (MySQL ENUM/SET, PostgreSQL UUID/JSONB/arrays, MSSQL UNIQUEIDENTIFIER/NVARCHAR, SQLite type affinity)
6363
- **Database Migrations** - Version-controlled schema changes with rollback support (Yii2-inspired)
6464
- **Advanced Pagination** - Full, simple, and cursor-based pagination with metadata
6565
- **Export Helpers** - Export results to JSON, CSV, and XML formats
@@ -233,7 +233,7 @@ Comprehensive, runnable examples are available in the [`examples/`](examples/) d
233233
- **[Architecture](examples/08-architecture/)** - Read/write splitting, sharding, load balancing
234234
- **[ActiveRecord](examples/09-active-record/)** - Object-based operations, relationships, scopes
235235
- **[Extensibility](examples/10-extensibility/)** - Macros, plugins, event dispatcher
236-
- **[Schema Management](examples/11-schema/)** - DDL Query Builder, migrations
236+
- **[Schema Management](examples/11-schema/)** - DDL Query Builder, migrations, dialect-specific types
237237
- **[Reliability](examples/12-reliability/)** - Exception handling, connection retry, error diagnostics
238238
- **[Miscellaneous](examples/14-misc/)** - Examples extracted from this README
239239

@@ -342,12 +342,26 @@ $db = new PdoDb('mysql', [
342342
### Step 3: Create Table
343343

344344
```php
345+
// Simple approach (raw SQL)
345346
$db->rawQuery('CREATE TABLE users (
346347
id INTEGER PRIMARY KEY AUTOINCREMENT,
347348
name TEXT,
348349
email TEXT,
349350
age INTEGER
350351
)');
352+
353+
// Or use DDL Query Builder with dialect-specific types
354+
$db->schema()->createTable('products', [
355+
'id' => $db->schema()->primaryKey(),
356+
'name' => $db->schema()->string(255)->notNull(),
357+
'status' => $db->schema()->enum(['draft', 'published', 'archived']) // MySQL ENUM
358+
->defaultValue('draft'),
359+
'uuid' => $db->schema()->uuid(), // PostgreSQL UUID, MySQL CHAR(36), MSSQL UNIQUEIDENTIFIER
360+
'tags' => $db->schema()->array('TEXT'), // PostgreSQL TEXT[], others JSON
361+
'metadata' => $db->schema()->jsonb(), // PostgreSQL JSONB, others JSON
362+
'is_active' => $db->schema()->boolean()->defaultValue(true),
363+
'created_at' => $db->schema()->timestamp()->defaultExpression('CURRENT_TIMESTAMP')
364+
]);
351365
```
352366

353367
### Step 4: CRUD Operations

0 commit comments

Comments
 (0)