Bdf Prime ORM

v2.1.1 2024-02-26 09:58 UTC


Prime is a Data mapper ORM based on doctrine DBAL. The goal of prime is to lightweight usage of data mapper and doctrine DBAL.

build Scrutinizer Code Quality codecov Packagist Version Total Downloads Type Coverage

Getting Started

See Wiki for more information

composer require b2pweb/bdf-prime

use Bdf\Prime\ConnectionManager;
use Bdf\Prime\Entity\Model;
use Bdf\Prime\Mapper\Mapper;
use Bdf\Prime\Mapper\Builder\FieldBuilder;
use Bdf\Prime\Mapper\Builder\IndexBuilder;
use Bdf\Prime\Query\Expression\Like;
use Bdf\Prime\ServiceLocator;

// Declare your entity
class User extends Model
    public $id;
    public $firstName;
    public $lastName;
    public $email;

    public function __construct(array $data) 

// Declare the data mapper for the entity
class UserMapper extends Mapper
    public function schema(): array
        return [
            'connection' => 'myDB',
            'table'      => 'users',
    public function buildFields(FieldBuilder $builder): void

    public function buildIndexes(IndexBuilder $builder): void

// Declare your connections
$connexions = new ConnectionManager();
$connexions->declareConnection('myDB', 'mysql://myuser:mypassword@localhost');

// Use the service locator to locate your repositories
$manager = new ServiceLocator($connexions);
$repository = $manager->repository(User::class);

// Get and update an entity
$user = User::findById(1);

// Use a query builder for searching entities 
User::where('firstName', 'john')->orWhere('email', (new Like('john%'))->startsWith())->all();