assegaiphp / orm
AssegaiORM is a standalone ORM for modern PHP applications, with optional AssegaiPHP integration.
Requires
- php: >=8.3
- ext-curl: *
- ext-intl: *
- ext-pdo: *
- ext-pdo_mysql: *
- ext-pdo_pgsql: *
- ext-pdo_sqlite: *
- assegaiphp/util: ^0.4.4
- predis/predis: ^2.3
- psr/log: ^3.0
- symfony/console: ^7.1
Requires (Dev)
Suggests
- assegaiphp/console: Optional: enables Assegai CLI installers and ORM command discovery.
- assegaiphp/core: Optional: enables framework-aware config and repository integration inside Assegai applications.
- dev-main
- 0.8.2
- 0.8.1
- 0.8.0
- 0.7.9
- 0.7.8
- 0.7.7
- 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-3
- dev-copilot/update-release-plan
- dev-amasiye-patch-2
- dev-amasiye-patch-1
This package is auto-updated.
Last update: 2026-04-03 20:21:34 UTC
README
A standalone ORM for modern PHP applications, with optional AssegaiPHP integration.
Description
An object-relational mapper for modern PHP applications. You can use it on its own, or plug it into AssegaiPHP when you want repository injection and framework conventions.
Installation
$ assegai add orm
That is the preferred path inside an Assegai workspace. It will:
- require
assegaiphp/ormif it is missing - import
OrmModuleinto the root module - make the ORM CLI commands available through package discovery
If you install the package manually first, assegai add orm is still safe to run afterward. It will just finish the
workspace wiring.
For standalone PHP projects that are not using Assegai, install the package directly:
$ composer require assegaiphp/orm
Guide map
This package is designed to feel familiar to teams coming from TypeORM:
- entities describe persistence shape
- repositories can be used directly or injected into services in Assegai
- data sources decide where a feature reads and writes
- relations are explicit and ownership matters
- migrations evolve the schema deliberately
In the main Assegai guide set, the ORM track is:
core/docs/data-and-orm.mdcore/docs/orm-setup-and-data-sources.mdcore/docs/orm-entities-repositories-and-results.mdcore/docs/orm-relations.mdcore/docs/orm-migrations-and-database-workflows.md
Quick Start
Using it without Assegai
You can use AssegaiORM directly in any PHP project. The standalone path is:
- configure named databases for the ORM runtime
- create a
DataSource - create or fetch repositories from that data source
<?php use App\Entities\NoteEntity; use Assegai\Orm\DataSource\DataSource; use Assegai\Orm\DataSource\DataSourceOptions; use Assegai\Orm\Enumerations\DataSourceType; use Assegai\Orm\Support\OrmRuntime; OrmRuntime::configure([ 'databases' => [ 'sqlite' => [ 'app' => [ 'path' => __DIR__ . '/storage/app.sqlite', ], ], ], ]); $dataSource = new DataSource(new DataSourceOptions( name: 'app', type: DataSourceType::SQLITE, database: 'app', )); $notes = $dataSource->getRepository(NoteEntity::class); $note = $notes->create((object)[ 'title' => 'First note', 'body' => 'Stored without a framework', ]); $created = $notes->save($note); $allNotes = $notes->find()->getData();
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 NoteEntity { #[PrimaryGeneratedColumn] public ?int $id = null; #[Column(type: ColumnType::VARCHAR, nullable: false)] public string $title = ''; #[Column(type: ColumnType::TEXT, nullable: true)] public ?string $body = null; }
Relation mental model
Relations follow the same ownership ideas you would expect from TypeORM:
OneToOne: the owner side has#[JoinColumn(...)]ManyToOneandOneToMany: the foreign key lives on theManyToOnesideManyToMany: the owner side has#[JoinTable(...)]
Load relations explicitly in find() and findOne() calls, and prefer writing through the owner side of the relation.
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\NoteEntity; 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(NoteEntity::class); $newNote = $notes->create([ 'title' => 'First note', 'body' => 'Stored in SQLite', ]); $notes->insert($newNote); $allNotes = $notes->find()->getData(); $firstNote = $notes->findOne(['id' => 1])->getFirst();
Using it inside Assegai
Inside Assegai, import OrmModule once or let assegai add orm wire it for you. That module registers the repository
resolver so #[InjectRepository(...)] can participate in the framework injector cleanly.
Once the module is present, you can inject the repository and let the entity metadata select the SQLite connection:
<?php namespace App\Notes; use App\Entities\NoteEntity; use Assegai\Core\Attributes\Injectable; use Assegai\Orm\Attributes\InjectRepository; use Assegai\Orm\Management\Repository; #[Injectable] class NotesService { public function __construct( #[InjectRepository(NoteEntity::class)] private readonly Repository $notes, ) { } public function all(): array { return $this->notes->find()->getData(); } }
Standalone first, framework optional
The ORM no longer needs assegaiphp/core to function. When the core package is present, the ORM can still read
framework config and repository metadata automatically. When it is not present, Assegai\\Orm\\Support\\OrmRuntime
acts as the lightweight runtime seam for config, module options, and logging.
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.