Download the PHP package ascetic-soft/rowcast without Composer
On this page you can find all versions of the php package ascetic-soft/rowcast. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ascetic-soft/rowcast
More information about ascetic-soft/rowcast
Files in ascetic-soft/rowcast
Package rowcast
Short Description Lightweight DataMapper and QueryBuilder over PDO with DTO hydration and type casting
License MIT
Informations about the package rowcast
Rowcast
Lightweight DataMapper over PDO for PHP 8.4+.
Rowcast maps database rows to DTOs and back using reflection, supports explicit/auto mapping, type conversion, and includes a fluent query builder with dialect-aware UPSERT.
Documentation: English | Русский | LLM/Context7
Requirements
- PHP >= 8.4
ext-pdo
Installation
Quick Start
Core Concepts
Rowcast supports two mapping styles:
- Auto mapping — pass
class-stringfor reads and table name for writes. Names are converted viaNameConverterInterface(default:SnakeCaseToCamelCase). - Explicit mapping — pass
Mappingto control table name, column/property pairs, and ignored properties.
Auto Mapping
Table name is derived from DTO class name for reads:
| Class | Table |
|---|---|
User |
users |
UserProfile |
user_profiles |
Column/property conversion (default):
| Column | Property |
|---|---|
created_at |
createdAt |
is_active |
isActive |
Explicit Mapping
Use Mapping::explicit(...) when only declared columns must be used:
Notes:
Mappingis currently mutable and configured in place.- Prefer building it once during setup and then reusing it as configuration.
- Avoid mutating the same
Mappinginstance after it is already shared across multiple operations or services.
Connection
Connection wraps PDO and provides query helpers, transaction API, nested transaction support (savepoints), and query-builder factory.
Create Connection
Raw Queries
Query Events
Register lightweight listeners to observe SQL execution.
Transactions
Nested mode creates savepoints for inner transactions.
DataMapper API
Main methods:
insert(string|Mapping $target, object $dto): voidbatchInsert(string|Mapping $target, array $dtos, ?int $maxBindParameters = null): voidupdate(string|Mapping $target, object $dto, array $where): intbatchUpdate(string|Mapping $target, array $dtos, array $identityProperties, ?int $maxBindParameters = null): voiddelete(string|Mapping $target, array $where): intfindAll(string|Mapping $target, array $where = [], array $orderBy = [], ?int $limit = null, ?int $offset = null): arrayiterateAll(string|Mapping $target, array $where = [], array $orderBy = [], ?int $limit = null, ?int $offset = null): iterablefindOne(string|Mapping $target, array $where = []): ?objectsave(string|Mapping $target, object $dto, string ...$identityProperties): voidupsert(string|Mapping $target, object $dto, string ...$conflictProperties): intbatchUpsert(string|Mapping $target, array $dtos, array $conflictProperties, ?int $maxBindParameters = null): voidhydrate(...),hydrateAll(...),extract(...)
CRUD Example
save(...) Example
save(...) checks row existence by identity columns, then performs insert or update.
Notes:
save(...)is a convenience API and does a read-before-write flow.- It does not require a database conflict constraint to exist.
- It may use two SQL statements for one logical save operation.
- Prefer
upsert(...)when your database and schema support conflict handling and write-path efficiency matters.
upsert(...) Example
Batch operations
batchInsert and batchUpsert automatically split large input into chunks based on DB parameter limits (for example, SQLite: 999 bind params), while executing all chunks inside one transaction.
Advanced where in DataMapper
DataMapper passes where arrays to the same QueryBuilder condition engine, so advanced operators are available there as well:
Type Conversion
Rowcast converts DB values to declared PHP property types on hydrate, and PHP values to DB-safe values on extract/write.
Built-in converters:
ScalarConverter(int,float,string)BoolConverter(bool<->0/1)DateTimeConverter(DateTimeInterface<-> formatted UTC string)JsonConverter(array<-> JSON)EnumConverter(BackedEnum<-> backing value)
Custom Type Converter
Implement TypeConverterInterface and pass a custom registry to DataMapper:
Custom Name Converter
Implement NameConverterInterface and pass it to DataMapper:
Query Builder
Connection::createQueryBuilder() provides a fluent SQL builder.
SELECT
For pagination, use:
setOffset(int $offset)— start rowsetLimit(int $limit)— max rows
You can also pass associative arrays to where(), andWhere(), and orWhere():
array predicates are converted to field = :param expressions joined by AND:
where(['a' => 1, 'b' => 2])->a = :w_a AND b = :w_bandWhere(['a' => 1])appends anotherANDblockorWhere(['a' => 1])wraps previous predicate:(prev OR a = :w_a)
Parameter names are generated automatically and made unique (:w_id, :w_id_1, ...).
Supported array operators:
Operator reference:
| Input | Example | SQL fragment (shape) |
|---|---|---|
| Equality | ['id' => 10] |
id = :w_id |
IS NULL |
['deleted_at' => null] |
deleted_at IS NULL |
IS NOT NULL |
['deleted_at !=' => null] |
deleted_at IS NOT NULL |
IN (auto) |
['status' => ['active', 'pending']] |
status IN (:w_status, :w_status_1) |
NOT IN (auto) |
['status !=' => ['banned']] |
status NOT IN (:w_status, ...) |
IN (explicit) |
['status IN' => ['active']] |
status IN (:w_status) |
NOT IN (explicit) |
['status NOT IN' => ['banned']] |
status NOT IN (:w_status) |
| Comparison | ['age >=' => 18] |
age >= :w_age |
LIKE |
['name LIKE' => 'A%'] |
name LIKE :w_name |
ILIKE |
['name ILIKE' => 'a%'] |
name ILIKE :w_name |
NOT LIKE |
['name NOT LIKE' => '%bot%'] |
name NOT LIKE :w_name |
NOT ILIKE |
['name NOT ILIKE' => '%bot%'] |
name NOT ILIKE :w_name |
BETWEEN |
['age BETWEEN' => [18, 65]] |
age BETWEEN :w_age AND :w_age_1 |
Notes:
- Empty
INarray compiles to1 = 0(always false). - Empty
NOT INarray compiles to1 = 1(always true). ILIKEandNOT ILIKEare PostgreSQL-specific.BackedEnumvalues are normalized to backing scalar values inWHEREparameters (includingIN/NOT INarrays).
Dialect-specific operator support:
| Dialect | Extra operators over base set |
|---|---|
PostgreSQL (pgsql) |
ILIKE, NOT ILIKE |
MySQL (mysql) |
none |
SQLite (sqlite) |
none |
| Generic/other drivers | none |
Base set for all dialects: >, >=, <, <=, LIKE, NOT LIKE.
OR Conditions
You can compose OR logic in two ways.
Method-based OR groups:
Combine with existing filters:
Nested-key style in one array:
OR composition reference:
| Pattern | Example | SQL fragment (shape) |
|---|---|---|
whereOr(...groups) |
->whereOr(['status' => 'active'], ['role' => 'admin']) |
((status = :w_status) OR (role = :w_role)) |
andWhereOr(...groups) |
->where(['deleted_at' => null])->andWhereOr(['status' => 'active'], ['role' => 'admin']) |
deleted_at IS NULL AND ((status = :w_status) OR (role = :w_role)) |
$or inside where([...]) |
->where(['age >' => 18, '$or' => [['status' => 'active'], ['role' => 'admin']]]) |
age > :w_age AND ((status = :w_status) OR (role = :w_role)) |
$and inside $or |
->where(['$or' => [['status' => 'active'], ['$and' => [['role' => 'admin'], ['verified' => true]]]]]) |
((status = :w_status) OR ((role = :w_role) AND (verified = :w_verified))) |
| Mixed operators in OR groups | ->whereOr(['status' => ['active', 'pending'], 'deleted_at' => null], ['name LIKE' => 'A%', 'age BETWEEN' => [18, 65]]) |
((status IN (...) AND deleted_at IS NULL) OR (name LIKE :w_name AND age BETWEEN :w_age AND :w_age_1)) |
INSERT / UPDATE / DELETE
UPSERT
Upsert is compiled via SQL dialects:
MysqlDialectPostgresDialectSqliteDialectGenericDialect(throws for unsupported UPSERT)
WHERE array operator support is also dialect-aware (for example, ILIKE/NOT ILIKE only for PostgreSQL).
Architecture
Development
License
MIT
All versions of rowcast with dependencies
ext-pdo Version *