PHPackages                             hgraca/micro-orm - 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. hgraca/micro-orm

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

hgraca/micro-orm
================

A very small ORM library

16

Since Dec 16Compare

[ Source](https://github.com/hgraca/php-micro-orm)[ Packagist](https://packagist.org/packages/hgraca/micro-orm)[ RSS](/packages/hgraca-micro-orm/feed)WikiDiscussions Synced 2d ago

READMEChangelogDependenciesVersions (2)Used By (0)

Hgraca\\MicroOrm
================

[](#hgracamicroorm)

[![Author](https://camo.githubusercontent.com/e80528a6fbd7a1766b221b1a32d700b339f6a1992a8e0a1f602d24c256c74d66/687474703a2f2f696d672e736869656c64732e696f2f62616467652f617574686f722d406867726163612d626c75652e7376673f7374796c653d666c61742d737175617265)](https://www.herbertograca.com)[![Software License](https://camo.githubusercontent.com/942e017bf0672002dd32a857c95d66f28c5900ab541838c6c664442516309c8a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Latest Version](https://camo.githubusercontent.com/35bb51a899de992d3f1171d434db7a70e8fe400e7e142bf8f8dea81c704a3d90/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6867726163612f7068702d6d6963726f2d6f726d2e7376673f7374796c653d666c61742d737175617265)](https://github.com/hgraca/php-micro-orm/releases)[![Total Downloads](https://camo.githubusercontent.com/fec0d3f4996be596003cd3c3bee73321eab0deb67223ca2f3603fc99054b744e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6867726163612f6d6963726f2d6f726d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hgraca/micro-orm)

[![Build Status](https://camo.githubusercontent.com/3a48e2f1a3a7d555a9444be47b7ec0c544246963247241efa8ccd9f9bccc4475/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f6275696c642f672f6867726163612f7068702d6d6963726f2d6f726d2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/hgraca/php-micro-orm/build)[![Coverage Status](https://camo.githubusercontent.com/fb7953e66f51c49fc94f196a974dffc20732415908698ae87d3602e0443c2f60/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6867726163612f7068702d6d6963726f2d6f726d2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/hgraca/php-micro-orm/code-structure)[![Quality Score](https://camo.githubusercontent.com/766a4217f5ba6d44abf1d695a88322b85ba683e8e42104b6288778eb1e4ef4d1/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6867726163612f7068702d6d6963726f2d6f726d2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/hgraca/php-micro-orm)

A very small ORM library. It doesnt have any kind of caching, nor instance management. I've built it as a learning tool and maybe at some point it will be usable, but always as a very thin layer.

Usage
-----

[](#usage)

### Config

[](#config)

The config can be something like:

```
[
    'repositoryFqcn' => MySqlPdoRepository::class,
    'dateTimeFormat' => 'Y-m-d H:i:s',
    'collectionFqcn' => Collection::class
    'dataMapper' => [
        Entity::class => [
            'entityFcqn'                 => Entity::class,
            // if not set, it will be inferred from the entity name,
            // if it doesnt exit, the default Repository will be used
            'repositoryFqcn'             => EntityRepository::class,
            'table'                      => ClassHelper::extractCanonicalClassName(Entity::class),
            'propertyToColumnNameMapper' => array_combine($properties, $properties),
            'collectionFqcn'             => Collection::class,
            'attributes' => [
                'id' => [ // by convention its always 'id'
                    'column' => 'id',
                    'type' => 'integer', // by convention its always an integer
                ],
                'aProperty' => [
                    'column' => 'aColumn_name',
                    'type' => 'integer', // integer, float, boolean, string, text, datetime
                ],
            ],
        ],
    ],
]
```

### Querying

[](#querying)

For simple queries we can use the client `select` method as:

```
$table = 'DummyTable';
$filter = [
    'propA' => true,
    'propB' => null,
    'propC' => ['filterC1' => 5, 'filterC2' => null],
];
$orderBy = [
    'propA' => 'ASC',
    'propB' => 'DESC',
];

$this->client->select($table, $filter, $orderBy);
```

And the code above generates the following SQL:

```
SELECT *
FROM `DummyTable`
WHERE
    `propA`=:propA_filter
    AND `propB` IS :propB_filter
    AND (`propC`=:filterC1_filter OR `propC` IS :filterC2_filter)
ORDER BY propA ASC, propB DESC
```

But for more complex queries we should do them custom and just pass them to the client `executeQuery` method, ie:

```
$sql = 'SELECT *
        FROM `DummyTable`
        WHERE
            `propA`=:propA_filter
            AND `propB` IS :propB_filter
            AND (`propC`=:filterC1_filter OR `propC` IS :filterC2_filter)
        ORDER BY propA ASC, propB DESC';

$filter = [
    'propA' => true,
    'propB' => null,
    'propC' => ['filterC1' => 5, 'filterC2' => null],
];

$this->executeQuery($sql, $filter);
```

### Conventions

[](#conventions)

- All entities have an ID, who's property name is 'id', column name is 'id' and type is int
- The default DB to be used is the first registered

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

[](#installation)

To install the library, run the command below and you will get the latest version:

```
composer require hgraca/micro-orm

```

Tests
-----

[](#tests)

To run the tests run:

```
make test
```

Or just one of the following:

```
make test-acceptance
make test-functional
make test-integration
make test-unit
make test-humbug
```

To run the tests in debug mode run:

```
make test-debug
```

Coverage
--------

[](#coverage)

To generate the test coverage run:

```
make coverage
```

Code standards
--------------

[](#code-standards)

To fix the code standards run:

```
make cs-fix
```

Todo
----

[](#todo)

- Cleanup and test Repository
- Cleanup and test DataMapper
- Cleanup and test Config
- Document how to use repositories and query classes, and how not to
- Create a relational config format, like the Doctrine yml config, but with arrays
- Implement lazy loading
- Create an EntityManager, management so we only save entities in the end of the request and works as a 1st level cache
- Implement 2nd level caching
- Implement eager loading

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/4af14428505ab93e698bb1fa7a540b0f71dbae0246b6c534f39011aaafc13717?d=identicon)[hgraca](/maintainers/hgraca)

---

Top Contributors

[![hgraca](https://avatars.githubusercontent.com/u/1809002?v=4)](https://github.com/hgraca "hgraca (2 commits)")

### Embed Badge

![Health badge](/badges/hgraca-micro-orm/health.svg)

```
[![Health](https://phpackages.com/badges/hgraca-micro-orm/health.svg)](https://phpackages.com/packages/hgraca-micro-orm)
```

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M117](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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