assegaiphp / orm
AssegaiORM is an ORM written in modern PHP. It supports both Active Record and Data Mapper patterns. AssegaiORM is highly influenced by other ORMs, such as TypeORM, Doctrine and Entity Framework.
Requires
- php: >=8.3
- ext-curl: *
- ext-intl: *
- ext-pdo: *
- ext-pdo_mysql: *
- ext-pdo_pgsql: *
- ext-pdo_sqlite: *
- assegaiphp/core: ^0.7.0
- assegaiphp/util: ^0.4.4
- predis/predis: ^2.3
- symfony/console: ^7.1
Requires (Dev)
- dev-main
- 0.7.6
- 0.7.5
- 0.7.4
- 0.7.3
- 0.7.2
- 0.7.1
- 0.7.0
- 0.6.32
- 0.6.31
- 0.6.30
- 0.6.29
- 0.6.28
- 0.6.27
- 0.6.26
- 0.6.25
- 0.6.24
- 0.6.23
- 0.6.22
- 0.6.21
- 0.6.20
- 0.6.19
- 0.6.18
- 0.6.17
- 0.6.16
- 0.6.15
- 0.6.14
- 0.6.13
- 0.6.12
- 0.6.11
- 0.6.10
- 0.6.9
- 0.6.8
- 0.6.7
- 0.6.6
- 0.6.5
- 0.6.4
- 0.6.3
- 0.6.2
- 0.6.1
- 0.6.0
- 0.5.1
- 0.5.0
- 0.4.11
- 0.4.10
- 0.4.9
- 0.4.8
- 0.4.7
- 0.4.6
- 0.4.5
- 0.4.4
- 0.4.3
- 0.4.2
- 0.4.1
- 0.4.0
- 0.3.1
- 0.3.0
- 0.2.7
- 0.2.6
- 0.2.5
- 0.2.4
- 0.2.3
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.1
- 0.1.0
- dev-develop
- dev-amasiye-patch-2
- dev-amasiye-patch-1
This package is auto-updated.
Last update: 2026-03-15 19:19:18 UTC
README
A progressive PHP framework for building efficient and scalable server-side applications.
Description
An object-relational mapper for AssegaiPHP.
Installation
$ composer require assegaiphp/orm
Quick Start
Using SQLite
SQLite is a good fit for local development, small apps, prototypes, and CLI tools. This ORM supports SQLite through PDO, so the first step is to register a named SQLite connection in your app config.
Make sure the pdo_sqlite extension is enabled and that the folder for your database file already exists. The
configured path should be relative to your project's working directory.
<?php return [ 'databases' => [ 'sqlite' => [ 'app' => [ 'path' => 'storage/database/app.sqlite', ], ], ], ];
You can then point an entity at that SQLite data source:
<?php namespace App\Entities; use Assegai\Orm\Attributes\Columns\Column; use Assegai\Orm\Attributes\Columns\PrimaryGeneratedColumn; use Assegai\Orm\Attributes\Entity; use Assegai\Orm\Enumerations\DataSourceType; use Assegai\Orm\Queries\Sql\ColumnType; #[Entity( table: 'notes', database: 'app', driver: DataSourceType::SQLITE, )] class Note { #[PrimaryGeneratedColumn] public ?int $id = null; #[Column(type: ColumnType::VARCHAR, nullable: false)] public string $title = ''; #[Column(type: ColumnType::TEXT, nullable: true)] public ?string $body = null; }
If you want to use SQLite directly through the ORM, create a DataSource, ensure the table exists, and then work with
the repository:
<?php use App\Entities\Note; use Assegai\Orm\DataSource\DataSource; use Assegai\Orm\DataSource\DataSourceOptions; use Assegai\Orm\Enumerations\DataSourceType; $dataSource = new DataSource(new DataSourceOptions( entities: [], name: 'app', type: DataSourceType::SQLITE, )); $dataSource->manager->query(<<<SQL CREATE TABLE IF NOT EXISTS `notes` ( `id` INTEGER PRIMARY KEY AUTOINCREMENT, `title` TEXT NOT NULL, `body` TEXT ) SQL); $notes = $dataSource->getRepository(Note::class); $newNote = $notes->create([ 'title' => 'First note', 'body' => 'Stored in SQLite', ]); $notes->insert($newNote); $allNotes = $notes->find()->getData(); $firstNote = $notes->findOne(['id' => 1])->getFirst();
In an Assegai application, you can also inject the repository and let the entity metadata select the SQLite connection:
<?php namespace App\Notes; use App\Entities\Note; use Assegai\Core\Attributes\Injectable; use Assegai\Orm\Attributes\InjectRepository; use Assegai\Orm\Management\Repository; #[Injectable] class NotesService { public function __construct( #[InjectRepository(Note::class)] private readonly Repository $notes, ) { } public function all(): array { return $this->notes->find()->getData(); } }
Support
Assegai is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.
Stay in touch
- Author - Andrew Masiye
- Website - https://assegaiphp.com
- Twitter - @assegaiphp
License
Assegai is MIT licensed.