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 today

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

24

—

LowBetter than 31% of packages

Maintenance43

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity38

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

455d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8907905?v=4)[Leon M. Saia](/maintainers/leonmsaia)[@leonmsaia](https://github.com/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

[jdorn/sql-formatter

a PHP SQL highlighting library

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

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

8351.6M87](/packages/propel-propel1)[pgvector/pgvector

pgvector support for PHP

198741.5k12](/packages/pgvector-pgvector)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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