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

ActiveLibrary

phore/orm
=========

Object Relational Mapper

v1.2.1(1y ago)167MITPHPPHP &gt;=8.1

Since Jul 10Pushed 1y ago1 watchersCompare

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

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

Phore MiniSql
=============

[](#phore-minisql)

Overview
--------

[](#overview)

Phore MiniSql is a lightweight ORM library for PHP, providing an easy-to-use interface for database operations such as create, read, update, delete (CRUD), and schema management. This README provides detailed usage instructions, including entity definitions, handling operations, indexes, foreign keys, and table/connection maintenance.

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

[](#installation)

To install Phore MiniSql, use Composer:

```
composer require phore/minisql
```

Defining Entities
-----------------

[](#defining-entities)

Entities are defined as PHP classes with public properties representing the columns of the corresponding database table. Each entity class must implement a static `__schema` method that returns an `OrmClassSchema` object.

```
namespace App\Entity;

use Phore\MiniSql\Schema\OrmClassSchema;

class User
{
    public int $id;
    public string $name;
    public string $email;

    public static function __schema(): OrmClassSchema
    {
        return new OrmClassSchema(
            tableName: 'users',
            primaryKey: 'id',
            autoincrement: true,
            columns: [
                'id' => 'int',
                'name' => 'varchar(255)',
                'email' => 'varchar(255)'
            ]
        );
    }
}
```

Usage
-----

[](#usage)

### Connecting to the Database

[](#connecting-to-the-database)

To connect to the database, create an instance of the `Orm` class and provide the DSN and entity classes.

```
use Phore\MiniSql\Orm;
use App\Entity\User;

$orm = new Orm([User::class], 'mysql:host=localhost;dbname=testdb;user=root;password=root');
$orm->connect();
```

### Creating Records

[](#creating-records)

To create a new record, instantiate the entity class, set its properties, and call the `create` method.

```
$user = new User();
$user->name = 'John Doe';
$user->email = 'john.doe@example.com';
$orm->create($user);
```

### Reading Records

[](#reading-records)

To read a record by its primary key, use the `read` method.

```
$user = $orm->withClass(User::class)->read(1);
```

### Updating Records

[](#updating-records)

To update a record, modify its properties and call the `update` method.

```
$user->name = 'Jane Doe';
$orm->update($user);
```

### Deleting Records

[](#deleting-records)

To delete a record, call the `delete` method.

```
$orm->delete($user);
```

### Listing All Records

[](#listing-all-records)

To list all records of an entity, use the `listAll` method.

```
$users = $orm->withClass(User::class)->listAll();
```

### Selecting Records with Conditions

[](#selecting-records-with-conditions)

To select records with specific conditions, use the `select` method.

```
$users = $orm->withClass(User::class)->select(['name' => 'Jane Doe']);
```

Indexes
-------

[](#indexes)

Indexes can be defined in the `OrmClassSchema` using the `indexes` property.

```
public static function __schema(): OrmClassSchema
{
    return new OrmClassSchema(
        tableName: 'users',
        primaryKey: 'id',
        autoincrement: true,
        columns: [
            'id' => 'int',
            'name' => 'varchar(255)',
            'email' => 'varchar(255)'
        ],
        indexes: [
            'idx_name' => ['name'],
            'idx_email' => ['email']
        ]
    );
}
```

Foreign Keys
------------

[](#foreign-keys)

Foreign keys can be defined in the `OrmClassSchema` using the `foreignKeys` property.

```
use Phore\MiniSql\Schema\OrmForeignKey;

public static function __schema(): OrmClassSchema
{
    return new OrmClassSchema(
        tableName: 'orders',
        primaryKey: 'id',
        autoincrement: true,
        columns: [
            'id' => 'int',
            'user_id' => 'int',
            'product_id' => 'int'
        ],
        foreignKeys: [
            new OrmForeignKey('user_id', 'users', 'id'),
            new OrmForeignKey('product_id', 'products', 'id')
        ]
    );
}
```

Maintaining Tables and Connections
----------------------------------

[](#maintaining-tables-and-connections)

### Updating Schema

[](#updating-schema)

To update the database schema based on the defined entities, use the `updateSchema` method.

```
$orm->updateSchema();
```

### Dropping All Tables

[](#dropping-all-tables)

To drop all tables in the database, use the `dropAllTables` method.

```
$orm->getDriver()->getSchemaUpdater()->dropAllTables();
```

Conclusion
----------

[](#conclusion)

Phore MiniSql provides a simple and efficient way to manage database operations in PHP. By defining entities and using the provided methods, you can easily perform CRUD operations, manage indexes and foreign keys, and maintain your database schema.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 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

676d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/878a384d056698a2400e4b7c8858db05a6caebb2c560e67151be36d46d58def0?d=identicon)[dermatthes](/maintainers/dermatthes)

---

Top Contributors

[![dermatthes](https://avatars.githubusercontent.com/u/13380559?v=4)](https://github.com/dermatthes "dermatthes (5 commits)")

### Embed Badge

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

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

PHPackages © 2026

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