ascetic-soft/rowcast-bundle
Symfony bundle integrating ascetic-soft/rowcast connection and DataMapper, with optional rowcast-schema migrations/services and console commands. Supports SQL profiler integration, configurable DSN/auth/options, transactions, schema paths, and query profiling thresholds.
Install the Bundle:
composer require ascetic-soft/rowcast-bundle
Ensure AsceticSoft\RowcastBundle\RowcastBundle::class is registered in config/bundles.php.
Configure config/packages/rowcast.yaml:
rowcast:
connection:
dsn: '%env(DATABASE_DSN)%'
username: '%env(DATABASE_USER)%'
password: '%env(DATABASE_PASSWORD)%'
First Use Case: Query Execution
Inject DataMapper into a service/repository and execute queries:
use AsceticSoft\Rowcast\DataMapper;
final readonly class UserRepository {
public function __construct(private DataMapper $mapper) {}
public function findById(int $id): ?array {
return $this->mapper->fetchOne('SELECT * FROM users WHERE id = :id', ['id' => $id]);
}
}
Schema Definition
#[Rowcast\Table] and related attributes:
#[Rowcast\Table(name: 'users')]
#[Rowcast\Column(name: 'id', type: 'integer', primary: true)]
class User {}
schema.php or YAML/JSON files (pointed to by rowcast.schema.path).Data Access
DataMapper for CRUD operations:
// Insert
$this->mapper->execute('INSERT INTO users (name) VALUES (:name)', ['name' => 'Alice']);
// Fetch
$users = $this->mapper->fetchAll('SELECT * FROM users WHERE active = :active', ['active' => true]);
Migrations
bin/console rowcast:make
bin/console rowcast:migrate
Console Queries
bin/console rowcast:query "SELECT * FROM users WHERE id = :id" --param id=1
DataMapper results to form components for type-safe data handling.DataMapper as a custom data provider for hydrating resources.DataMapper to log queries or transform results (e.g., for API responses).Schema Parser Conflicts
rowcast.schema.path points to a directory, ensure ascetic-soft/rowcast-schema is installed for attribute parsing. Otherwise, fall back to file-based parsing.composer require ascetic-soft/rowcast-schema
Profiler Overhead
rowcast.profiler.enabled) collects query data in memory. For high-traffic apps, limit max_queries to avoid memory spikes.# config/packages/prod/rowcast.yaml
rowcast:
profiler:
enabled: false
Transaction Nesting
nest_transactions: true enables nested transactions. If your database driver doesn’t support savepoints (e.g., MySQL in some configurations), disable it:
rowcast:
connection:
nest_transactions: false
Migration Table Collisions
_rowcast_migrations) might conflict with existing tables. Customize:
rowcast:
schema:
migration_table: app_migrations
options:
rowcast:
connection:
options:
PDO::ATTR_ERRMODE: PDO::ERRMODE_EXCEPTION
PDO::ATTR_EMULATE_PREPARES: false
Custom Query Builders
Override DataMapper to add domain-specific query methods:
class CustomDataMapper extends DataMapper {
public function findActiveUsers(): array {
return $this->fetchAll('SELECT * FROM users WHERE active = 1');
}
}
Register it as a service alias.
Schema Extensions
Extend SchemaParserInterface to support custom attributes or validation rules.
Connection Decorators
Decorate Connection to add middleware (e.g., query logging, caching):
$connection = new ConnectionDecorator($originalConnection, function ($query) {
// Log or transform $query
});
How can I help you explore Laravel packages today?