PHPackages                             rotexsoft/leanorm - 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. rotexsoft/leanorm

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

rotexsoft/leanorm
=================

A Generic Data Objects ( https://github.com/rotexsoft/gdao ) implementation based on a stripped down version of idiorm (\\LeanOrm\\DBConnector). A light-weight, highly performant PHP data access library.

6.0.0(5mo ago)4421↓60%[13 issues](https://github.com/rotexsoft/leanorm/issues)BSD-3-ClausePHPPHP &gt;=8.2CI passing

Since Feb 21Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/rotexsoft/leanorm)[ Packagist](https://packagist.org/packages/rotexsoft/leanorm)[ Docs](https://github.com/rotexsoft/leanorm)[ RSS](/packages/rotexsoft-leanorm/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (10)Dependencies (10)Versions (41)Used By (0)

[![Run PHP Tests and Code Quality Tools](https://github.com/rotexsoft/leanorm/actions/workflows/php.yml/badge.svg)](https://github.com/rotexsoft/leanorm/actions/workflows/php.yml) [![GitHub release (latest SemVer)](https://camo.githubusercontent.com/8ebcb82b7b8efce242b9bd22bb747e7750a0e1aa3f73925b0804239b41111e1d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f726f746578736f66742f6c65616e6f726d)](https://camo.githubusercontent.com/8ebcb82b7b8efce242b9bd22bb747e7750a0e1aa3f73925b0804239b41111e1d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f726f746578736f66742f6c65616e6f726d) [![GitHub](https://camo.githubusercontent.com/7267bb3f354ea6f26198ba5876b3ec25d53e5f918bd07c9ee48ac4c0fae11bf5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f726f746578736f66742f6c65616e6f726d)](https://camo.githubusercontent.com/7267bb3f354ea6f26198ba5876b3ec25d53e5f918bd07c9ee48ac4c0fae11bf5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f726f746578736f66742f6c65616e6f726d) [![Coverage Status](https://camo.githubusercontent.com/af28f7af37f956aaa2380705dcd30b802d2b78e0d7fb4e66d75a28b83649dea6/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f726f746578736f66742f6c65616e6f726d2f62616467652e737667)](https://coveralls.io/github/rotexsoft/leanorm) [![GitHub code size in bytes](https://camo.githubusercontent.com/63a82cb631b4d316e5f5521b5c6ba74afc78200ff5caf04ea5998ba98e6d053f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f726f746578736f66742f6c65616e6f726d)](https://camo.githubusercontent.com/63a82cb631b4d316e5f5521b5c6ba74afc78200ff5caf04ea5998ba98e6d053f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f726f746578736f66742f6c65616e6f726d)

[![GitHub top language](https://camo.githubusercontent.com/c0c94bae09b532f378e1486e1272eee8300e60f7676205ae044dbf9766a2e5b7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f746f702f726f746578736f66742f6c65616e6f726d)](https://camo.githubusercontent.com/c0c94bae09b532f378e1486e1272eee8300e60f7676205ae044dbf9766a2e5b7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f746f702f726f746578736f66742f6c65616e6f726d) [![Packagist PHP Version Support](https://camo.githubusercontent.com/7b5608da377cb2fd85fea3c4fe40339573379f4ab2fc5b843ad1871325ae2081/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f726f746578736f66742f6c65616e6f726d)](https://camo.githubusercontent.com/7b5608da377cb2fd85fea3c4fe40339573379f4ab2fc5b843ad1871325ae2081/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f726f746578736f66742f6c65616e6f726d) [![GitHub commits since latest release (by date)](https://camo.githubusercontent.com/ba2c132fd13198f64f4a99285a639afb1a0115d1da10fd5a21c6dade77b06755/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6d6d6974732d73696e63652f726f746578736f66742f6c65616e6f726d2f6c6174657374)](https://camo.githubusercontent.com/ba2c132fd13198f64f4a99285a639afb1a0115d1da10fd5a21c6dade77b06755/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6d6d6974732d73696e63652f726f746578736f66742f6c65616e6f726d2f6c6174657374) [![GitHub last commit](https://camo.githubusercontent.com/73848ae7b0b3c90851aa3232a0782d946361de9152e2056b4917e59aa9226b57/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f726f746578736f66742f6c65616e6f726d)](https://camo.githubusercontent.com/73848ae7b0b3c90851aa3232a0782d946361de9152e2056b4917e59aa9226b57/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f726f746578736f66742f6c65616e6f726d) [![GitHub Release Date](https://camo.githubusercontent.com/a93552e71af6d70e9b231214a65eedcdd0d759a583c764b32470433f3a352599/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652d646174652f726f746578736f66742f6c65616e6f726d)](https://camo.githubusercontent.com/a93552e71af6d70e9b231214a65eedcdd0d759a583c764b32470433f3a352599/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652d646174652f726f746578736f66742f6c65616e6f726d) [![Libraries.io dependency status for GitHub repo](https://camo.githubusercontent.com/86e8f367d87e5497b0d4ac4e3090d4a18487e5947822341b1e49b76010526a84/68747470733a2f2f696d672e736869656c64732e696f2f6c6962726172696573696f2f6769746875622f726f746578736f66742f6c65616e6f726d)](https://libraries.io/packagist/rotexsoft%2Fleanorm)

LeanOrm
=======

[](#leanorm)

[![Leanorm](./leanorm.png)](./leanorm.png)

#### A light-weight, highly performant PHP data access library. Good alternative to Doctrine &amp; Eloquent without all the bells &amp; whistles that are not needed in most applications.

[](#a-light-weight-highly-performant-php-data-access-library-good-alternative-to-doctrine--eloquent-without-all-the-bells--whistles-that-are-not-needed-in-most-applications)

Installation Requirements
-------------------------

[](#installation-requirements)

PHP 8.2+ for version 6.x &amp; 7.x

PHP 8.1+ for versions 4.x &amp; 5.x

PHP 7.4+ for versions 2.x &amp; 3.x

[Composer](https://getcomposer.org/)

Versions 2.x &amp; 3.x of this package have been rigorously tested against sqlite 3.7.11+, MySQL 8.0.29+ &amp; PostgreSQL 15.1+.

Version 4.x &amp; 5.x have been rigorously tested against:

- Sqlite 3.34.1+
- MariaDB 10.4.33+, 10.5.24+, 10.6.17+, 10.11.7+, 11.0.5+, 11.1.4+, 11.2.3+ &amp; 11.4.2+
- MySQL 5.6.51, 5.7.44, 8.0.36+, 8.1.0, 8.2.0, 8.3.0+ &amp; 8.4+
- PostgreSQL 12.18+, 13.14+, 14.11+, 15.6+ &amp; 16.2+
- See [run-tests-against-multiple-db-versions.php](./run-tests-against-multiple-db-versions.php)

Version 6.x &amp; 7.x have been rigorously tested against:

- Sqlite 3.46.1
- MariaDB 10.4.34, 10.5.29, 10.6.25, 10.11.16, 11.4.10, 11.8.6 &amp; 12.2.2
- MySQL 5.6.51, 5.7.44, 8.0.45, 8.4.8 &amp; 9.6.0
- PostgreSQL 12.22, 13.23, 14.22, 15.17, 16.13, 17.9 &amp; 18.3
- See [run-tests-against-multiple-db-versions.php](./run-tests-against-multiple-db-versions.php) &amp; [run-tests-against-multiple-db-versions-docker.php](./run-tests-against-multiple-db-versions-docker.php)

MS SQL Server, is theoretically supported but hasn't been tested. Will provide more updates on MS SQL Server support once testing on that DB engine has been done.

If you are using Sqlite, version sqlite 3.7.11 or higher is required.

Version 1.x of this package never got a stable release.

Version 2.x+ of this package is stable &amp; uses [**aura/sqlquery**](https://github.com/auraphp/Aura.SqlQuery/tree/2.8.1#select) 2.8.0+ .

Version 3.x+ and higher of this package are also stable &amp; use [**aura/sqlquery**](https://github.com/auraphp/Aura.SqlQuery/blob/3.x/docs/select.md) 3.0.0+.

Versions 2.x &amp; 3.x mainly differ in the versions of **aura/sqlquery** their **Model::getSelect(): \\Aura\\SqlQuery\\Common\\Select** returns and 3.x has a few newer features like **Model::fetchOneByPkey($id, array $relations\_to\_include = \[\]): ?\\GDAO\\Model\\RecordInterface**.

> Deprecated **Utils::search2D(...)** in 2.x has been removed in 3.x

Version 6.x is not backwards compatible with 7.x.

Version 5.x is not backwards compatible with 4.x.

Version 4.x is not backwards compatible with 3.x.

Versions 2.x, 3.x &amp; 4.x are feature complete as of July 2024, only bug fixes will be applied to those versions.

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

[](#installation)

> `composer require rotexsoft/leanorm`

There's an accompanying [command-line tool](https://github.com/rotexsoft/leanorm-cli) that can be used to automatically generate Model, Record &amp; Collection classes for the tables and views in a database. To install this tool, just run the command below. Read the [documentation](https://github.com/rotexsoft/leanorm-cli/blob/main/README.md) for the tool for more information.

> `composer require --dev rotexsoft/leanorm-cli`

Running Tests
-------------

[](#running-tests)

> `./vendor/bin/phpunit --coverage-text`

> You can set the environment variable **LEANORM\_PDO\_DSN** with a valid $dsn string for pdo e.g. LEANORM\_PDO\_DSN=sqlite::memory:

- For Postgres, the dsn must include **dbname=blog** and you should make sure a blog database exists in the Postgres instance. You don't need this for Sqlite, MariaDB or MySql, the database will be programmatically created.

> You can set the environment variable **LEANORM\_PDO\_USERNAME** with a valid $username string for pdo if needed e.g. LEANORM\_PDO\_USERNAME=jblow

> You can set the environment variable **LEANORM\_PDO\_PASSWORD** with a valid $password string for pdo if needed e.g. LEANORM\_PDO\_PASSWORD=some\_password

> For example:

> `LEANORM_PDO_DSN=sqlite::memory: LEANORM_PDO_USERNAME=jblow LEANORM_PDO_PASSWORD=some_password ./vendor/bin/phpunit --coverage-text`

> `LEANORM_PDO_DSN="mysql:host=hostname_or_ip_address" LEANORM_PDO_USERNAME="jblow" LEANORM_PDO_PASSWORD="some_password" ./vendor/bin/phpunit --coverage-text`

### GDAO Classes &amp; Interfaces

[](#gdao-classes--interfaces)

> Take a look at the code for the most up to date listing of methods

[![GDAO Classes & Interfaces](https://raw.githubusercontent.com/rotexsoft/gdao/master/class-diagram.svg)](https://raw.githubusercontent.com/rotexsoft/gdao/master/class-diagram.svg)

### LeanORM Classes

[](#leanorm-classes)

> Take a look at the code for the most up to date listing of methods

- **\\LeanOrm\\Model** extends the abstract **\\GDAO\\Model** class
- **\\LeanOrm\\Model\\Record** &amp; **\\LeanOrm\\Model\\ReadOnlyRecord** both implement **\\GDAO\\Model\\RecordInterface**
- **\\LeanOrm\\Model\\Collection** implements **\\GDAO\\Model\\CollectionInterface**

[![LeanORM Classes](class-diagram.svg)](class-diagram.svg)

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

[](#documentation)

Documentation for the non-stable 1.x version of this package is located at

Documentation for version 2.x version can be found [here](https://github.com/rotexsoft/leanorm/blob/2.2.x/docs/index.md).

Documentation for version 3.x+ can be found [here](https://github.com/rotexsoft/leanorm/blob/3.x/docs/index.md).

Documentation for version 4.0.x+ can be found [here](https://github.com/rotexsoft/leanorm/blob/4.0.x/docs/index.md).

Documentation for version 4.1.x+ can be found [here](https://github.com/rotexsoft/leanorm/blob/4.1.x/docs/index.md).

Documentation for version 5.x+ can be found [here](https://github.com/rotexsoft/leanorm/blob/5.x/docs/index.md).

Documentation for version 6.x+ can be found [here](https://github.com/rotexsoft/leanorm/blob/6.x/docs/index.md).

Documentation for version 7.x+ can be found [here](https://github.com/rotexsoft/leanorm/blob/master/docs/index.md).

Please submit an issue (preferably with a pull request) to address mistakes or omissions in the documentation or to propose improvements to the documentation.

Contributing
------------

[](#contributing)

PHPUnit Tests are set-up to run in a specific order in **phpunit.xml.dist**.

Yes, the best practice is for tests to run independently of each other, but because there are fair amount of static methods in the DBConnector class, its tests need to be run first before other Test Classes.

New Test files must be manually added to the phpunit.xml.dist file in order for those new tests to run.

Class properties and method parameters and variables are all in snake case (e.g. $some\_property\_name).

### Branching

[](#branching)

These are the branches in this repository:

- **master:** contains code for the latest major version (7.x) of this package.
- **6.x:** contains code for the 6.x versions of this package. Only bug fixes should be added to this branch. This branch is feature complete.
- **5.x:** contains code for the 5.x versions of this package. Only bug fixes should be added to this branch. This branch is feature complete.
- **4.1.x:** contains code for the 4.1.x versions of this package. Only bug fixes should be added to this branch. This branch is feature complete.
- **4.0.x:** contains code for the 4.0.x versions of this package. Only bug fixes should be added to this branch. This branch is feature complete.
- **3.x:** contains code for the 3.x versions of this package. Only bug fixes should be added to this branch. This branch is feature complete.
- **2.2.x:** contains code for the 2.2.x versions of this package. Only bug fixes should be added to this branch. This branch is feature complete.
- **1.X:** contains code for the **1.X** versions of this package. This branch is abandoned.
- **gh-pages:** contains documentation for the 1.X versions of this package. This branch is abandoned.

###  Health Score

48

—

FairBetter than 94% of packages

Maintenance63

Regular maintenance activity

Popularity19

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity85

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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

Every ~65 days

Recently: every ~18 days

Total

40

Last Release

150d ago

Major Versions

3.0.3 → 4.0.22024-06-07

4.0.2 → 5.0.02024-07-21

2.4.0 → 3.1.02024-11-27

3.x-dev → 5.1.22025-11-13

5.x-dev → 6.0.02026-01-24

PHP version history (6 changes)1.0.0-RC1PHP &gt;=5.4.0

1.1.0-RC1PHP &gt;=5.6.0

1.1.1-RC2PHP &gt;=7.2

2.0.0-RC1PHP &gt;=7.4

4.0.0PHP &gt;=8.1

6.0.0PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/d90c6231900b4b0df89afeafc48b631c5b9f95c4295327d4c3753d053c6b4f62?d=identicon)[rotexdegba](/maintainers/rotexdegba)

---

Top Contributors

[![rotexdegba](https://avatars.githubusercontent.com/u/1242622?v=4)](https://github.com/rotexdegba "rotexdegba (236 commits)")

---

Tags

collectionsdata-mapperdata-mapper-patterndata-mappingdatabaseeager-loadinglazy-loadinglightweightmodelmysqlormpdophpphp-ormpostgresqlrecordssqlsqlitetable-data-gatewaydatadatabaseormmysqlsqlitepostgresqlsqlpdodbgatewaytableleantable data gatewaylean ormlean databaselean db

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm, Rector

Type Coverage Yes

### Embed Badge

![Health badge](/badges/rotexsoft-leanorm/health.svg)

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

###  Alternatives

[doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.

9.7k595.8M6.5k](/packages/doctrine-dbal)[aura/sqlquery

Object-oriented query builders for MySQL, Postgres, SQLite, and SQLServer; can be used with any database connection library.

4563.1M37](/packages/aura-sqlquery)[cycle/database

DBAL, schema introspection, migration and pagination

65746.2k48](/packages/cycle-database)[atlas/query

Object-oriented query builders and performers for MySQL, Postgres, SQLite, and SQLServer.

41253.7k7](/packages/atlas-query)[aura/sqlschema

Provides facilities to read table names and table columns from a database using PDO.

41240.2k4](/packages/aura-sqlschema)[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.

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

PHPackages © 2026

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