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

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

hegentopf/easy-orm
==================

Lightweight ORM for PHP with automatic model generation

0.1.3(6mo ago)011MITPHPPHP &gt;=8.1

Since Dec 28Pushed 6mo agoCompare

[ Source](https://github.com/hegentopf/easy-orm)[ Packagist](https://packagist.org/packages/hegentopf/easy-orm)[ RSS](/packages/hegentopf-easy-orm/feed)WikiDiscussions main Synced today

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

EasyORM Usage Guide
===================

[](#easyorm-usage-guide)

This document provides examples and explanations for using EasyORM, including model creation, query building, and fetching data.

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

[](#installation)

Install via Composer:

```
composer require hegentopf/easy-orm
```

Basic Usage
-----------

[](#basic-usage)

### Initial Setup for Creation and Usage

[](#initial-setup-for-creation-and-usage)

```
use Hegentopf\EasyOrm\connection\ConnectionManager;
use Hegentopf\EasyOrm\connection\MySQLConnection;

// Set up the database connection, adjust parameters as needed.
// Use .env or config files in production
$default = new MySQLConnection( 'dbName', 'user', 'passwd', 'localhost', 3306 );
ConnectionManager::setConnection( $default );

// For multiple connections, you can set and get connections by name
$replication = new MySQLConnection( 'dbName', 'user', 'passwd', 'localhost', 3307 );
ConnectionManager::setConnection( $replication, 'replication' );
```

### Model Creation

[](#model-creation)

```
use Hegentopf\EasyOrm\modelCreator\DbModelCreator;

$dbModelCreator = new DbModelCreator();
$dbModelCreator
    ->setNamespace( 'App\\dbModels' )
    ->setPath( __DIR__ . '/../src/dbModels' )
    ->createAllDbModels( true ); // true = override existing models
```

This will generate models for all tables in your current database.

### Using Models

[](#using-models)

```
use App\dbModels\test\ProductModel;

// Create a new model
$productModel = new ProductModel();
$productModel->setName( 'Screwdriver' )->setPrice( 15.40 )->save();

// Fetch all models
$productModel = ProductModel::getQueryBuilder()->get();

// Fetch a single model by primary key
$productModel = ProductModel::fetchById( 1 );

// Update a model
$productModel->setName( 'Nail' )->setPrice( 0.22 )->save();

// Delete a model
$productModel->delete();
```

### QueryBuilder Examples

[](#querybuilder-examples)

#### Simple Select

[](#simple-select)

```
use App\dbModels\test\ProductModel;

$productModels = ProductModel::getQueryBuilder()
    ->select( ProductModel::name(), ProductModel::price() )
    ->limit( 10 )
    ->get();
```

#### Select with Where, GroupBy, OrderBy

[](#select-with-where-groupby-orderby)

```
use App\dbModels\test\ProductModel;
use Hegentopf\EasyOrm\queryBuilder\OrderBy;

$products = ProductModel::getQueryBuilder()
                        ->select(
                                ProductModel::name(),
                                ProductModel::price(),
                                ProductModel::timestamp_created()
                            )
                        ->where( ProductModel::name(), '=', 'Screwdriver' )
                        ->groupBy( ProductModel::name() )
                        ->orderBy( ProductModel::name(), OrderBy::DESC )
                        ->limit( 3 )
                        ->get();
```

#### Joins

[](#joins)

```
use App\dbModels\test\OrderModel;
use App\dbModels\test\ProductModel;

$orders = OrderModel::getQueryBuilder()
                    ->select(
                        OrderModel::id(),
                        OrderModel::order_date(),
                        ProductModel::name(),
                        ProductModel::price()
                    )
                    ->leftJoin(
                        ProductModel::getTable(),
                        ProductModel::order_id(),
                        OrderModel::id()
                    )
                    ->orderBy( OrderModel::order_date() )
                    ->get();
```

#### Subqueries

[](#subqueries)

```
use App\dbModels\shop\OrderModel;
use App\dbModels\shop\ProductModel;

$subQuery = ProductModel::getQueryBuilder()
                        ->select( ProductModel::order_id() )
                        ->where( ProductModel::price(), '>', 100 )
                        ->groupBy( ProductModel::order_id() );

$orders = OrderModel::getQueryBuilder()
                    ->select(
                        OrderModel::id(),
                        OrderModel::order_date()
                    )
                    ->whereIn( OrderModel::id(), $subQuery )
                    ->get();
```

### Notes and Best Practices

[](#notes-and-best-practices)

- SQL-Injections are prevented by using prepared statements.
- Joined Data can be accessed via magic getters, e.g., `$model->getJoinedColumnName()`.
- Date, DateTime, and Timestamp columns are automatically converted to `DateTime` objects. Note that the DateTime object is a copy, so modifying it does not change the model's value. To change the value, use the setter method.
- Use `new DbExpression( 'NOW()' )` for raw SQL expressions when needed (⚠️ be aware of SQL-Injections).
- Use `take()` and `skip()` as alternatives to `limit()` and `offset()`.
- To fetch only one model, use `first()` instead of `get()` and you will receive a single model or `null`.
- Columns are automatically mapped to protected properties.
- Only changed Columns are updated in the database.
- Generated models follow camelCase conversion from table and column names. `order_items` → `orderItems`

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance68

Regular maintenance activity

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

187d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/113784801?v=4)[hegentopf](/maintainers/hegentopf)[@hegentopf](https://github.com/hegentopf)

---

Top Contributors

[![hegentopf](https://avatars.githubusercontent.com/u/113784801?v=4)](https://github.com/hegentopf "hegentopf (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[propel/propel1

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

8351.6M87](/packages/propel-propel1)[magento/magento2-functional-testing-framework

Magento2 Functional Testing Framework

15312.0M36](/packages/magento-magento2-functional-testing-framework)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)[liqueurdetoile/cakephp-orm-json

Cakephp plugin to provide easy control over JSON type fields in database

1463.9k](/packages/liqueurdetoile-cakephp-orm-json)[wrklst/docxmustache

docx template manipulation class, based on mustache templating language

578.7k](/packages/wrklst-docxmustache)

PHPackages © 2026

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