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.

Maintainers

Package info

github.com/assegaiphp/orm

pkg:composer/assegaiphp/orm

Statistics

Installs: 257

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.7.6 2026-03-15 16:43 UTC

README

Assegai Logo

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

Overview & Tutorial

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

License

Assegai is MIT licensed.