Rowcast
Lightweight DataMapper over PDO for PHP 8.4+ with DTO hydration and type casting.
Get Started Русский View on GitHub
What is Rowcast?
Rowcast is a modern, zero-dependency DataMapper for PHP 8.4+. It maps database rows to plain DTO objects and back using Reflection, with automatic type casting, naming convention support, and a fluent query builder.
Key Highlights
- Zero external dependencies — Only PHP 8.4 and the PDO extension required
- Automatic DTO mapping — Database rows hydrated to typed PHP objects via Reflection
- Type casting — Automatic conversion between PHP and database types (
DateTime,BackedEnum, scalars) - Two mapping modes — Auto mode with conventions or Explicit mode with
ResultSetMapping - Fluent query builder — Build complex SQL queries with a chainable API
- Snake-to-camel conversion —
snake_casecolumns map tocamelCaseproperties by default - Nested transactions — Savepoint-based transaction nesting support
- PHPStan Level 9 — Fully statically analyzed codebase
Quick Example
use AsceticSoft\Rowcast\Connection;
use AsceticSoft\Rowcast\DataMapper;
// Define a DTO
class User
{
public int $id;
public string $name;
public string $email;
}
// Connect and create a mapper
$connection = Connection::create('mysql:host=localhost;dbname=app', 'root', 'secret');
$mapper = new DataMapper($connection);
// Insert
$user = new User();
$user->name = 'Alice';
$user->email = 'alice@example.com';
$mapper->insert('users', $user);
// Find
$user = $mapper->findOne(User::class, ['id' => 1]);
That’s it. A few lines to get a fully working DataMapper with automatic type casting and DTO hydration.
Why Rowcast?
| Feature | Rowcast | Traditional ORMs |
|---|---|---|
| Zero external dependencies | Yes | Often many |
| Plain DTO objects (no base class) | Yes | Requires entity base |
| Automatic type casting | Yes | Manual or annotations |
| Convention-based mapping | Yes | Configuration files |
| Fluent query builder | Yes | Yes |
| Nested transactions (savepoints) | Yes | Some |
| PHPStan Level 9 | Yes | Varies |
| Learning curve | Minimal | Steep |
Requirements
- PHP >= 8.4
- PDO extension
Installation
composer require ascetic-soft/rowcast
Documentation
Getting Started
Installation, first DTO, and basic CRUD in 5 minutes.
Connection
PDO wrapper, raw queries, transactions, and savepoints.
DataMapper
Insert, update, delete, findAll, findOne, and iterateAll.
Mapping
Auto mode, explicit ResultSetMapping, and name converters.
Type Casting
Scalars, DateTime, BackedEnum, and custom type casters.
Query Builder
Fluent SQL builder for SELECT, INSERT, UPDATE, DELETE.
Hydration
Reflection-based hydrator and custom hydrator support.
API Reference
Complete reference for all public classes and methods.