Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Noorm Bundle Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require bisonlab/noorm-bundle
    

    Add the bundle to config/bundles.php:

    return [
        // ...
        BisonLab\NoOrmBundle\BisonLabNoOrmBundle::class => ['all' => true],
    ];
    
  2. 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'
    
  3. 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]);
        }
    }
    

Implementation Patterns

Core Workflows

  1. Simple Queries Use fetchAll() or fetchOne() for direct SQL execution:

    $users = $noOrm->fetchAll('SELECT * FROM users WHERE active = :active', ['active' => 1]);
    
  2. Prepared Statements Bind parameters safely:

    $user = $noOrm->fetchOne('SELECT * FROM users WHERE id = :id', ['id' => 1]);
    
  3. 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;
    }
    
  4. Result Mapping Transform raw results into objects:

    $users = $noOrm->fetchAll('SELECT * FROM users');
    $userObjects = array_map(function ($row) {
        return (object) $row;
    }, $users);
    

Integration Tips

  • Symfony Forms: Use fetchAll() to populate form choices dynamically.
  • APIs: Return raw arrays or mapped objects in JSON responses.
  • Caching: Cache frequent queries with Symfony’s cache system:
    $cache = $this->get('cache.app');
    $users = $cache->get('users', function () use ($noOrm) {
        return $noOrm->fetchAll('SELECT * FROM users');
    });
    

Gotchas and Tips

Pitfalls

  1. No ORM Features

    • No relationships, eager loading, or complex object hydration. Use raw SQL or manual mapping.
    • Example: Avoid expecting $user->posts to work; fetch posts separately.
  2. Parameter Binding

    • Always use named parameters (: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]);
      
  3. Connection Management

    • The bundle uses Symfony’s Doctrine\DBAL under the hood. Ensure your DATABASE_URL is correctly configured in .env.
  4. Error Handling

    • Wrap queries in try-catch blocks to handle exceptions (e.g., connection failures):
      try {
          $noOrm->execute('...');
      } catch (\Doctrine\DBAL\Exception $e) {
          // Log or rethrow
      }
      

Debugging Tips

  • 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.

Extension Points

  1. 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');
        }
    }
    
  2. 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()->
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours