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

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

tabusoft/orm
============

Simple ORM and entity manager

2.0.6(5y ago)066[1 issues](https://github.com/alveoten/orm/issues)GPL-3.0+PHPPHP ^7.4CI failing

Since Jul 2Pushed 5y agoCompare

[ Source](https://github.com/alveoten/orm)[ Packagist](https://packagist.org/packages/tabusoft/orm)[ RSS](/packages/tabusoft-orm/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (5)Versions (41)Used By (0)

Tabusoft/ORM
============

[](#tabusoftorm)

Tabusoft/ORM is an entity and relationship manager.

- Simply create Entities and Repositories with command line script
- Help you to build query entity based. You will use Entities to get Entities, you don't need to convert query output to entities!
- All foreigns keys relations between tables will mapped, help you to write queries, or simply lazy load the related entities.

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

[](#installation)

You can install it with composer

```
$ composer require tabusoft/orm
```

Use the entity manager
----------------------

[](#use-the-entity-manager)

To use the entity manager we must create all entities and repository. The meaning of those two words will explain in the next paragraph. We have two command lines utilities: orm-cli and create-config.

### Create the config.json

[](#create-the-configjson)

create-config could be use to create a config.json files to use as parameter for orm-cli.

```
$ ./create-config --mysql --host=localhost --user=root --password=password --port=3306 --database-name=mydb --output-file=destination.json --output-type=json
```

You may specify a lot of config options. Please read the help:

```
$ ./create-config --help
```

### Create the enities

[](#create-the-enities)

The entities object are a 1 to 1 description of DB's table or collection. The class ar stored in the selected namespace under the "Entities" directory. Entities classes use a Trait that contains all the properties and setters and getters. Repository are use to manage the DB persistance and are stored in the selected namespace under the folder Repositories. Repositories classes use a Trait that contains all the info to grant the persistence.

To create these files you can use: orm-cli

```
$ ./orm-cli install config.json
```

To only update "Descriptors" without change the user edited Entities

```
$ ./orm-cli update config.json
```

#### Entities restrictions

[](#entities-restrictions)

Some tips to create your tables on MySQL DB.

- The table must have an id column as Primary key.
- If you have a view the view must have an id unique column. Be smart with the creation.
- the relation will be create with the foreign keys. You may create your relations, after.
- The Repository can use differnt dbs from each others. But you cannot join with the EQB tables that differ in DB's host or port.

Use the entities
----------------

[](#use-the-entities)

For example you will create these enities: (will be used in the below examples)

```

```

```

```

### Init the entitity

[](#init-the-entitity)

tabusoft/orm use massively tabusoft/db in the factory configuration you need to provide the same configuration of the tables. Please refer to [the documentation of that package](https://github.com/alveoten/db).

You can instantiate like an object:

```
//init the tabusoft/db
$db_config = new \Tabusoft\DB\DBFactoryConfig("localhost","test","test_username","test_password");
\Tabusoft\DB\DBFactory::getInstance($db_config);

//empty object
$category = new Application\Entities\Category();
```

Or you can retrieve it from db:

```
//obtain the repository
$repo = Application\Entities\ForumCategory()::getRepository();

//or
$repo = new Application\Repository\ForumCategoryRepository();

$category = $repo->findById(1323);
```

### Save (insert or update) the entity

[](#save-insert-or-update-the-entity)

The entity manager use a MySQL REPLACE command to insert or update the row in the DB. You can simply change your Entity properties and save it throw his repository.

```
$category->setCategoryName("New Category name");
$repo->save($category);
```

If you are saving a new Category object you must fill all non-nullable columns. Otherwise you will get an \\Exception.

### Lazy load

[](#lazy-load)

When you don't need performance you can use the foreign keys relations simple invoke the object. In the next example we have a relation from ForumTopics and ForumCategory. The lazy method appears directly in the entity descriptor.

```
$topics = ForumTopics::getRepository()->findBy("id",[1,2,3,4]);

foreach($topics as $topic) {
    dump($topic);

    $category = $topic->getForumCategory();

    dump($category);
}
```

Every time you call the getForumCategory() method you have a query. The result will be cached. Take care if you will use multiple requests.

Use the query builder
---------------------

[](#use-the-query-builder)

EQB is the Entity Query Builder. Give you the possibility to make queries without (if you want) enter to deeply into the DB structure. It have 3 special class: the EQB::Entity, the EQB::Column, the EQB::Function.

### The entities

[](#the-entities)

Wrap the Entities classes to one that could use into your query.

### The columns

[](#the-columns)

Maps the property to the columns. If you'll use a single column into the select you must specify the alias.

### The functions

[](#the-functions)

Maps the MySQL properties to the class utilities. If you'll use it in the select statement you need to specify an alias.

### Putting all together: the query

[](#putting-all-together-the-query)

The EQB object is the equivalent of the SQL query.

#### Simple select

[](#simple-select)

Let's put all togheter:

```
//init the query object
$query = new EQB();

//init two EQBEntity refered to the relative Entities class.
$fc = new EQBEntity(ForumCategory::class);
$ft = new EQBEntity(ForumTopics::class);

//doing a select:
//this will return two result containing:
//a ForumCategory entity, a ForumTopic entity,
//and the id column of forum category enitity.
$query = $q->select( $ft, $fc, $fc->id->as("id") );
$query->from($ft);
$query->where($fc->id, "IN (?)")->pushValue([1,2]);
$res = $query->query();

//or in the short mode:
$res = $q->select( $ft, $fc, $fc->id->as("id") )
            ->from($ft);
            ->where($fc->id, "IN (?)");
            ->query([1,2]);

//res is a traversable collection of: [ ForumTopic object, ForumCategory Object, id  ]
foreach($res as $r){
    var_dump($r);
}
```

#### Full explained JOIN

[](#full-explained-join)

To make a join:

```
$q = $q->select($ft,$fc)
    ->from($ft)
    ->join($fc, 'ON', $ft->idCategory, '=', $fc->id)
```

#### MySQL functions

[](#mysql-functions)

```
$q = $q->select(EQBFunction::COUNT('*')->as('num'))
    ->from($ft)
    ->leftjoin($fc)
    ->where(EQBFunction::ISNULL($fc->id);
```

### Fast Join

[](#fast-join)

As said we are mapping the foreign keys relation. In this mode we can create simple join. For each join will be search the related entity in the from and previus join. If there is no relation we search in the opposite direction. In that case first relation win.

```
$q = $q->select(*)
    ->from($ft)
    ->join($fc);
```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity74

Established project with proven stability

 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 ~18 days

Recently: every ~8 days

Total

40

Last Release

2158d ago

Major Versions

0.0.10 → 1.0.02019-01-22

1.8.3 → 2.0.02020-05-15

PHP version history (2 changes)0.0.1PHP ^7.0

2.0.0PHP ^7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/0582679befeef72125a4de979c817f977deeb1bd8f58b9d923d72645f09832c1?d=identicon)[alveoten](/maintainers/alveoten)

---

Top Contributors

[![alveoten](https://avatars.githubusercontent.com/u/31958626?v=4)](https://github.com/alveoten "alveoten (12 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[wouterj/eloquent-bundle

Implementing the Eloquent ORM into Symfony

166163.3k2](/packages/wouterj-eloquent-bundle)[pomm-project/pomm-bundle

The Symfony2 bundle for Pomm2

81198.7k4](/packages/pomm-project-pomm-bundle)[orchestra/database

Database Component for Orchestra Platform

201.4M578](/packages/orchestra-database)[cerbero/sql-dumper

Laravel package to dump SQL queries.

247.6k](/packages/cerbero-sql-dumper)

PHPackages © 2026

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