PHPackages                             getphred/pairity - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. getphred/pairity

ActiveLibrary[Database &amp; ORM](/categories/database)

getphred/pairity
================

DAO/DTO-centric PHP ORM with Query Builder, relations, migrations/CLI, Unit of Work, and event system. Supports MySQL/MariaDB, PostgreSQL, SQLite, SQL Server, and Oracle.

10PHPCI passing

Since Feb 8Pushed 3mo agoCompare

[ Source](https://github.com/getphred/pairity)[ Packagist](https://packagist.org/packages/getphred/pairity)[ RSS](/packages/getphred-pairity/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

Pairity ORM
===========

[](#pairity-orm)

[![Latest Version on Packagist](https://camo.githubusercontent.com/c0b45b2ff0d5d6ac8b3e1bae76d47154cdea725c707c45e92f823c4f236dd7ce/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f67657470687265642f706169726974792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/getphred/pairity)[![Total Downloads](https://camo.githubusercontent.com/bfbd610a923169bc225c31b3bfb9b9752be01f43fdad39b21bdc5d069ec16709/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f67657470687265642f706169726974792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/getphred/pairity)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

Pairity is a high-performance, partitioned-model PHP ORM that strictly separates data representation (DTO) from persistence logic (DAO). It provides a fluent Query Builder, robust relationship management, and enterprise-grade features like automatic multi-tenancy, auditing, and transparent attribute encryption.

Key Features
------------

[](#key-features)

- **Partitioned Model**: Clean separation between DTOs (Data) and DAOs (Persistence).
- **YAML-Driven Schema**: Define your tables in YAML; generate migrations and models automatically.
- **Fluent Query Builder**: Database-agnostic query construction with support for subqueries, joins, and set operations.
- **Relationships &amp; Eager Loading**: Efficiently handle BelongsTo, HasOne, HasMany, and Polymorphic relations with N+1 prevention.
- **Unit of Work**: Coordinate atomic updates across multiple connections with centralized transaction management.
- **Enterprise Features**:
    - **Automatic Multi-Tenancy**: Transparent data isolation via tenant scoping.
    - **Auditing**: Automatic change tracking for sensitive models.
    - **Concurrency Control**: Built-in Optimistic and Pessimistic locking.
    - **Attribute Encryption**: Transparent AES-256 encryption for PII data.
- **Developer Tooling**: First-class CLI (`pairity`) for code generation, migrations, seeding, and health checks.
- **Internationalization (i18n)**: Localized exception messages and CLI output (EN, ES, FR, DE, IT).

Installation
------------

[](#installation)

Install Pairity via Composer:

```
composer require getphred/pairity
```

Initialize the project structure (creates `schema/`, `src/Models/`, etc.):

```
vendor/bin/pairity init
```

Quick Start
-----------

[](#quick-start)

### 1. Define your Schema

[](#1-define-your-schema)

Create a YAML file in `schema/users.yaml` (Note: the `schema/` directory is automatically created by the `init` command):

```
columns:
  id:
    type: bigIncrements
  email:
    type: string
    unique: true
  password:
    type: string
    encrypted: true
  active:
    type: boolean
    default: true

relations:
  posts:
    type: hasMany
    target: posts
```

### 2. Generate Models

[](#2-generate-models)

```
vendor/bin/pairity make:model
```

### 3. Run Migrations

[](#3-run-migrations)

```
vendor/bin/pairity migrate
```

### 4. Usage

[](#4-usage)

#### Basic CRUD

[](#basic-crud)

```
use App\Models\DTO\UsersDTO;
use App\Models\DAO\UsersDAO;

$userDao = $container->get(UsersDAO::class);

// Create
$user = new UsersDTO(['email' => 'jane@example.com', 'password' => 'secret']);
$userDao->save($user);

// Read
$user = $userDao->find(1);
echo $user->email;

// Update
$user->setAttribute('active', false);
$userDao->save($user);
```

#### Query Builder

[](#query-builder)

```
$users = $userDao->query()
    ->where('active', true)
    ->whereIn('role', ['admin', 'editor'])
    ->orderBy('created_at', 'desc')
    ->limit(10)
    ->get();
```

#### Eager Loading

[](#eager-loading)

```
$users = $userDao->query()
    ->with('posts.comments')
    ->get();

foreach ($users as $user) {
    foreach ($user->posts as $post) {
        // Posts are already loaded!
    }
}
```

Documentation
-------------

[](#documentation)

For detailed documentation, please refer to the [SPECS.md](SPECS.md) file.

Testing
-------

[](#testing)

Run the test suite using PHPUnit:

```
vendor/bin/phpunit
```

License
-------

[](#license)

The MIT License (MIT). Please see [LICENSE.md](LICENSE.md) for more information.

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance55

Moderate activity, may be stable

Popularity2

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity14

Early-stage or recently created project

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

96d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/76918287c4577d7b4a6713f0d54f3de11e0d6a86f88bb2883b5dd0a19f80d87f?d=identicon)[getphred](/maintainers/getphred)

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/getphred-pairity/health.svg)

```
[![Health](https://phpackages.com/badges/getphred-pairity/health.svg)](https://phpackages.com/packages/getphred-pairity)
```

###  Alternatives

[getgrav/grav

Modern, Crazy Fast, Ridiculously Easy and Amazingly Powerful Flat-File CMS

15.4k84.1k1](/packages/getgrav-grav)[ryangjchandler/orbit

A flat-file database driver for Eloquent.

922256.2k5](/packages/ryangjchandler-orbit)[kimai/kimai

Kimai - Time Tracking

4.6k7.4k1](/packages/kimai-kimai)[kreait/firebase-bundle

Symfony Bundle for the Firebase Admin SDK

1534.7M2](/packages/kreait-firebase-bundle)[pixelfederation/doctrine-resettable-em-bundle

Symfony bundle for decorating default entity managers using a resettable decorator.

20113.5k](/packages/pixelfederation-doctrine-resettable-em-bundle)[tommyknocker/pdo-database-class

Framework-agnostic PHP database library with unified API for MySQL, MariaDB, PostgreSQL, SQLite, MSSQL, and Oracle. Query Builder, caching, sharding, window functions, CTEs, JSON, migrations, ActiveRecord, CLI tools, AI-powered analysis. Zero external dependencies.

845.7k](/packages/tommyknocker-pdo-database-class)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
