PHPackages                             leonmsaia/myorm - 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. leonmsaia/myorm

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

leonmsaia/myorm
===============

Mini ORM en PHP puro con soporte para relaciones, validaciones y soft deletes.

v1.0.0(1y ago)11MITPHPPHP &gt;=7.4

Since Apr 4Pushed 1y ago1 watchersCompare

[ Source](https://github.com/leonmsaia/myorm)[ Packagist](https://packagist.org/packages/leonmsaia/myorm)[ RSS](/packages/leonmsaia-myorm/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

MyORM - Mini ORM en PHP 🐘
=========================

[](#myorm---mini-orm-en-php-)

**MyORM** es una librería ORM (Object Relational Mapping) ligera escrita en PHP puro. Permite mapear tablas SQL a objetos PHP de forma sencilla, sin frameworks externos.

Ideal para proyectos chicos, educativos o scripts PHP organizados que necesiten:

- Acceso a bases de datos SQL (MySQL/MariaDB)
- Relaciones entre tablas
- Validaciones simples
- Soft deletes y timestamps automáticos (opcional)

---

🚀 Instalación
-------------

[](#-instalación)

1. Clona o descarga este repositorio.
2. Ejecutá `composer dump-autoload` si usás Composer (opcional).
3. Editá el archivo de configuración:

```
// myorm/config/database.php
return [
    'driver' => 'mysql',
    'host' => 'localhost',
    'database' => 'nombre_base',
    'username' => 'usuario',
    'password' => 'clave',
    'charset' => 'utf8mb4',
    'collation' => 'utf8mb4_unicode_ci',
    'audit' => true // Habilita created_at, updated_at, deleted_at
];
```

---

🧠 Ejemplo de uso
----------------

[](#-ejemplo-de-uso)

```
require_once 'myorm/src/ORM.php';

use MyORM\ORM;

// Conectarse
ORM::connect();

// Leer registros
$productos = ORM::table('products')->all();
print_r($productos);

// Crear nuevo
ORM::table('products')->create([
    'name' => 'Zapatilla',
    'price' => 1999.99
]);

// Actualizar
ORM::table('products')->update(1, [
    'price' => 1499.99
]);

// Eliminar (soft delete por defecto)
ORM::table('products')->delete(1);

// Hard delete
ORM::table('products')->delete(1, false);

// Validaciones
$errors = (new ORM())->validate([
    'email' => 'test@invalid'
], [
    'email' => 'required|email'
]);

if (!empty($errors)) {
    print_r($errors);
}
```

---

🔁 Relaciones
------------

[](#-relaciones)

```
// hasOne
$userProfile = (new ORM())->hasOne('profiles', 'user_id', 'id');

// belongsTo
$author = (new ORM())->belongsTo('users', 'author_id', 'id');

// hasMany
$posts = (new ORM())->hasMany('posts', 'user_id', 'id');
```

---

🧱 Estructura recomendada
------------------------

[](#-estructura-recomendada)

```
myorm/
├── config/
│   └── database.php
├── src/
│   └── ORM.php
├── examples/
│   └── example.php
├── README.md

```

---

🧪 SQL de ejemplo
----------------

[](#-sql-de-ejemplo)

```
CREATE TABLE `products` (
  `id` INT AUTO_INCREMENT PRIMARY KEY,
  `name` VARCHAR(100),
  `price` DECIMAL(10,2),
  `created_at` DATETIME NULL,
  `updated_at` DATETIME NULL,
  `deleted_at` DATETIME NULL
);
```

---

🧩 Requisitos
------------

[](#-requisitos)

- PHP 7.4+
- Extensión PDO habilitada
- MySQL / MariaDB

---

📌 Notas
-------

[](#-notas)

- Todas las consultas usan PDO con prepared statements.
- Si `audit` está en `true`, se agregan automáticamente `created_at`, `updated_at` y `deleted_at`.
- Si `audit` está en `false`, podés usar la base sin esas columnas.

---

📃 Licencia
----------

[](#-licencia)

MIT © 2025 - Creado por vos 💙

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance46

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity37

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

409d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/576ff738de673516a04977c7f48a394427241d34f02c8aeb7f273b19925c05aa?d=identicon)[leonmsaia](/maintainers/leonmsaia)

---

Top Contributors

[![leonmsaia](https://avatars.githubusercontent.com/u/8907905?v=4)](https://github.com/leonmsaia "leonmsaia (3 commits)")

### Embed Badge

![Health badge](/badges/leonmsaia-myorm/health.svg)

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

###  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)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

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

Reliese Components for Laravel Framework code generation.

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

Laravel Userstamps provides an Eloquent trait which automatically maintains `created\_by` and `updated\_by` columns on your model, populated by the currently authenticated user in your application.

7511.7M13](/packages/wildside-userstamps)

PHPackages © 2026

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