ascetic-soft/rowcast
Rowcast is a lightweight PDO DataMapper for PHP 8.4+. It maps DB rows to DTOs via reflection with auto/explicit mapping and type conversion, plus a fluent query builder with dialect-aware UPSERT.
DB::connection()). Can wrap Laravel’s DatabaseManager for unified access.Connection and DataMapper as singletons in Laravel’s container, replacing Eloquent models for specific use cases (e.g., read-heavy APIs, batch processing).DataMapper for DTO hydration/extraction in services, then expand to replace Eloquent queries where appropriate.DB facade to delegate to Rowcast’s Connection for specific tables.laravel-shift/database-to-dto).DB::transaction()).logs, analytics)?"php-attributes to auto-generate DTOs from migrations?"join, raw expressions)?DB::raw() syntax for complex SQL?" (Answer: No; requires custom QueryBuilder extensions.)DataMapper in unit tests or rewrite integration tests?"->where(['jsonb_column->>key' => 'value'])?" (Answer: Requires custom TypeConverter or QueryBuilder extension.)PDOException or wrap it in a custom exception?" (Answer: Throws PDOException; may need Laravel exception handler updates.)DB::statement(), DB::select(), and DB::table() calls with Rowcast’s Connection and DataMapper.Model::query()->get() → DataMapper::findAll(UserDto::class, [...])).Connection for consistency.DataMapper into services (e.g., UserService) for DTO-based operations.public function __construct(private DataMapper $mapper) {}
public function createUser(UserDto $dto): UserDto {
$this->mapper->insert('users', $dto);
return $dto;
}
ResourceController::index() → DataMapper::findAll(UserDto::class)).iterateAll() for paginated APIs to avoid loading all results into memory.taptapphp/bench for bulk inserts).RowcastServiceProvider to bind Connection and DataMapper to Laravel’s container.$this->app->singleton(DataMapper::class, fn() =>
new DataMapper(Connection::create(config('database.connections.mysql.dsn'), ...))
);
QueryBuilder to support Laravel-specific features (e.g., DB::raw).Rowcast::query() to mirror Laravel’s DB::query().rector/rector to auto-convert Eloquent models to DTOs.hasOne, belongsTo. Mitigate by:
DataMapper::findAll(UserDto::class, [...]) with joined DTOs).RelationDto classes.Model observers alongside Rowcast for hybrid setups.UserCreated::dispatch($dto)).where clauses are more explicit. Mitigate by:
QueryBuilder instances with pre-defined conditions.JsonConverter out of the box.QueryBuilder with raw SQL (e.g., ->where('MATCH(body) AGAINST(?))').DB::transaction(), but savepoints may not roll back as expected in all cases.Model::all(), Model::find(), and Model::where() with DataMapper::findAll()/findOne().// Before
User::where('active', true)->get();
// After
$mapper->findAll(UserDto::class, ['active' => true]);
Model::create(), Model::update() with DataMapper::insert()/update().// Before
User::create(['email
How can I help you explore Laravel packages today?