Skip to content

looserouting/orm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ORM

ORM for my Micro Framework

Example

Entity:

use Orm\Entity\BaseEntity;

#[Table('users')]
class User extends BaseEntity
{
    #[Column(name: 'id', type: 'INTEGER', primary: true, autoIncrement: true, nullable: false)]
    public ?int $id = null;

    #[Column(name: 'username', type: 'TEXT', nullable: false)]
    public string $username;
}

Repository:

 Orm\Repository\BaseRepository;

class UserRepository extends BaseRepository {}

Collection:

Transaction:

Migration:

php bin/migrate.php init

Mini-Test:

$pdo = new PDO('sqlite::memory:');
$repo = new UserRepository($pdo);
$user = new User();
$user->username = "test";
$repo->save($user);

print_r($repo->find($user->id));

You may want to add this scripts into composer.json of your project

{
  "scripts": {
    "create": "php vendor/looserouting/orm/bin/create.php entity",
    "migrate": "php vendor/looserouting/orm/bin/migrate.php"
  }
}

About

ORM for my Micro Framework

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages