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

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

phpgt/orm
=========

Object relational mapper.

01[4 issues](https://github.com/phpgt/Orm/issues)[3 PRs](https://github.com/phpgt/Orm/pulls)PHPCI passing

Since Apr 22Pushed 1mo ago1 watchersCompare

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

READMEChangelogDependenciesVersions (10)Used By (0)

This repository is currently in a prototype stage. I'm planning on building it out properly, but it may never get completed, or I might change it completely without notice.

Please don't use on anything real until a stable release is made!

Notes
-----

[](#notes)

Basic table creation is possible like this:

```
$generator = new SchemaGenerator();
$studentSchemaTable = $generator->generate(Student::class);
```

Then the `$studentSchemaTable` can be passed to the actual underlying database for it to execute as SQL.

For example:

```
$db->executeSQL($studentSchemaTable);
```

Here's an example of what the `Student` class looks like, and how the `SchemaGenerator` stringifies it as SQLite:

```
readonly class Student {
	public function __construct(
		public int $id,
		public string $name,
		public DateTime $dob,
	) {}
}
```

```
create table `Student` (
	`id` int not null primary key,
	`name` text not null,
	`dob` int not null
)
```

Some questions I need to answer before I go any further:

- How should the `DateTime` class be cast back and forth between different database engines? MySQL has a `datetime` type, but SQLite has to use a timestamp.
- How should the different constraints be handled? I like the idea of adding an attribute to describe the primary key: `#[PrimaryKey("id", PrimaryKey::AUTOINCREMENT)]`
- Straight-up foreign keys should be easy to implement - use a class as a public property.
- A common OOP technique is to have an array/iterable of objects. For example, the `Lesson` class can have an `array` or a custom `StudentCollection` class.
- This means a `StudentCollection` must be a differently derived class than `Student`, as it represents a junction table.

One big question I have yet to prototype:

- Cyclic dependencies are OK and sometimes really useful, especially in OOP land, but a recursive SQL query would be really inefficient on big data structures.
- The foreign key should not be loaded until it's used in code (lazy load), but this is going to require some clever programming for a good developer experience.

I think the way this should work is foreign keys are never done using joins - instead, separate queries should always be used. That way, the query that loads the referenced table will not need to be executed until the developer requests that field.

This could be achieved by the Orm generating an anonymous class that extends the referenced class, but takes on a trait to allow `__get` to execute the query... something like that, but I expect weird reflection will be required to make this transparent to the developer.

Proudly sponsored by
====================

[](#proudly-sponsored-by)

[JetBrains Open Source sponsorship program](https://www.jetbrains.com/community/opensource/)

[![JetBrains logo.](https://camo.githubusercontent.com/b5639e7738c6dfae9fe3f3e20175570b7376ce2577a772e09c25c2d4f14bf86e/68747470733a2f2f7265736f75726365732e6a6574627261696e732e636f6d2f73746f726167652f70726f64756374732f636f6d70616e792f6272616e642f6c6f676f732f6a6574627261696e732e737667)](https://www.jetbrains.com/community/opensource/)

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance60

Regular maintenance activity

Popularity1

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity23

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/9e42344b91ce4b91ab57875969f67a0a6a48de570a08bc65d673b06b72fd3a3f?d=identicon)[g105b](/maintainers/g105b)

---

Top Contributors

[![g105b](https://avatars.githubusercontent.com/u/358014?v=4)](https://github.com/g105b "g105b (9 commits)")

### Embed Badge

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

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

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

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

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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