From the Terminal

I "Rewrote" My ORM Again.

I added a Factory so the ORM could be tested, kept Model::getByID for compatibility, added SQLite, rebuilt hydration with reflection, and somehow this stopped being a refactor and became Divergence v3.

For the longest time I've preferred `Model::getByID` but it's kinda a problem for writing unit tests when all your code is set up that way. Let's just say for reasons it's better to have a Factory class. But then I just kept Model::getByID and it bubbles up to an actual factory with a series of stubs.

So you can still do it that way but now you can write tests that do things. Yay wonderful tests.

 

I really wanted to add sqlite support so that happened. Postgres is coming shortly.

I guess I sorta "finished" basically the vision which is full attribute driven definitions on models and setup appropriate abstraction layers for different connection engines.

<?php
namespace technexus\Models;

use Divergence\Models\Mapping\Column;
use Divergence\Models\Mapping\Relation;

class BlogPost extends \Divergence\Models\Model
{
    use \Divergence\Models\Relations;

    public static $tableName = 'blog_posts';
    
    private string $Title;
    private string $Permalink;
    private string $MainContent;

    #[Column(type:"timestamp",notnull:false)]
    private $Edited;

    private string $Status;
    
    #[Relation(
        type: 'one-one',
        class: User::class,
        local: 'CreatorID',
        foreign: 'ID'
    )]
    protected $Creator;

    #[Relation(
        type: 'one-many',
        class: PostTags::class,
        local: 'ID',
        foreign: 'BlogPostID'
    )]
    protected $Tags;
 
New Hydration Method

Late static binding and instantiating ourselves in the model the classic way and instead just use reflections to generate a "fake" object based on the Model's class and hydrate it again with reflections. That's pretty much the "magic trick" that allows full DTO mapping in PHP land. 

Anyway here's version 3 of Divergence.

It's running this site too.

 

Here are my benchmarks right now 

 

The next step is to scaffold some first to save() profilers against some of these and honestly write some better benchmarks. But I never really thought I'd get to hit this milestone so soon. So that's nice.