Lightweight ORM for Doctrine DBAL

When you need to prototype an app with database access it's occasionally nice to have a middle ground between writing raw queries and using a full ORM package.

When you need to prototype an app with database access it's occasionally nice to have a middle ground between writing raw queries and using a full ORM package.

SlimModel is designed to fill this gap, providing a very thin wrapper around native DBAL objects. As a bonus you can define your database state in your model classes and, while you are in development mode, you can enjoy automatic database synchronisation.

How it looks

Here's an example to get you started, first up, a model class:

use SlimModel\Base;

class Example extends Base {

    public $table = "example";
    $primary_key  = "id";

    public function setup() {
        $this->define("id",   "integer",  ["autoincrement"=>true]);
        $this->define("title","string",   []);
    }

}

That's all you need to start writing to an example table in your database.

Queries

Follows standard ORM syntax, the example table can be manipulated like:

$model =  new Example($db_connection);
$result = $model->insert(["title"=>"Hello World"]);

$row = (new Example($db_connection))->find(1);
print_r($row);
// Outputs: ["id"=>1,"title"=>"Hello World"]

Try It Out

The github repo is here: SlimModel install is easy via composer.