bisonlab/noorm-bundle
Symfony bundle for bisonlab/noorm that wires a lightweight, No-ORM data access layer into your app. Provides service configuration and integration so you can run queries and map results without a full ORM, keeping persistence simple and fast.
Installation
composer require bisonlab/noorm-bundle
Add the bundle to config/bundles.php:
return [
// ...
BisonLab\NoOrmBundle\BisonLabNoOrmBundle::class => ['all' => true],
];
Configuration
Define your database connection in config/packages/bisonlab_no_orm.yaml:
bisonlab_no_orm:
dbal:
connections:
default:
url: '%env(DATABASE_URL)%'
driver: 'pdo_mysql'
First Query
Use the NoOrm service to fetch data:
use BisonLab\NoOrmBundle\NoOrm;
class SomeController
{
public function __construct(private NoOrm $noOrm) {}
public function index()
{
$users = $this->noOrm->fetchAll('SELECT * FROM users');
return $this->render('users/index.html.twig', ['users' => $users]);
}
}
Simple Queries
Use fetchAll() or fetchOne() for direct SQL execution:
$users = $noOrm->fetchAll('SELECT * FROM users WHERE active = :active', ['active' => 1]);
Prepared Statements Bind parameters safely:
$user = $noOrm->fetchOne('SELECT * FROM users WHERE id = :id', ['id' => 1]);
Transactions Wrap operations in transactions:
$noOrm->beginTransaction();
try {
$noOrm->execute('UPDATE accounts SET balance = balance - :amount WHERE id = :id', [
'amount' => 100,
'id' => 123
]);
$noOrm->commit();
} catch (\Exception $e) {
$noOrm->rollBack();
throw $e;
}
Result Mapping Transform raw results into objects:
$users = $noOrm->fetchAll('SELECT * FROM users');
$userObjects = array_map(function ($row) {
return (object) $row;
}, $users);
fetchAll() to populate form choices dynamically.$cache = $this->get('cache.app');
$users = $cache->get('users', function () use ($noOrm) {
return $noOrm->fetchAll('SELECT * FROM users');
});
No ORM Features
$user->posts to work; fetch posts separately.Parameter Binding
:param) for security. Avoid string concatenation:
// UNSAFE
$noOrm->fetchAll("SELECT * FROM users WHERE id = $id");
// SAFE
$noOrm->fetchAll('SELECT * FROM users WHERE id = :id', ['id' => $id]);
Connection Management
Doctrine\DBAL under the hood. Ensure your DATABASE_URL is correctly configured in .env.Error Handling
try-catch blocks to handle exceptions (e.g., connection failures):
try {
$noOrm->execute('...');
} catch (\Doctrine\DBAL\Exception $e) {
// Log or rethrow
}
Enable DBAL Logging
Add to config/packages/dev/bisonlab_no_orm.yaml:
bisonlab_no_orm:
dbal:
logging: true
Logs will appear in var/log/dev.log.
Query Validation
Use Doctrine\DBAL\Connection::getSchemaManager()->createSchemaSql() to validate table structures.
Custom Query Builders
Extend the bundle by creating a service to wrap NoOrm with domain-specific methods:
// src/Service/UserRepository.php
class UserRepository
{
public function __construct(private NoOrm $noOrm) {}
public function findActiveUsers(): array
{
return $this->noOrm->fetchAll('SELECT * FROM users WHERE active = 1');
}
}
Event Listeners
Listen to kernel.request to log queries or modify them:
// src/EventListener/QueryLogger.php
class QueryLogger implements KernelEventSubscriber
{
public function onKernelRequest(GetResponseEvent $event)
{
$noOrm = $event->getContainer()->
How can I help you explore Laravel packages today?