PHPackages                             plasma/schemas - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. plasma/schemas

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

plasma/schemas
==============

Schemas map any data source into a PHP object.

v0.4.0(5y ago)22762Apache-2.0PHPPHP &gt;=7.1CI failing

Since Jan 29Pushed 4y agoCompare

[ Source](https://github.com/PlasmaPHP/schemas)[ Packagist](https://packagist.org/packages/plasma/schemas)[ RSS](/packages/plasma-schemas/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (5)Dependencies (4)Versions (6)Used By (0)

Schemas [![CI status](https://github.com/PlasmaPHP/schemas/workflows/CI/badge.svg)](https://github.com/PlasmaPHP/schemas/actions)
=================================================================================================================================

[](#schemas-)

Schemas is a simple Object Relational Mapper (ORM) for Plasma. Schemas maps any data source into a PHP object.

Getting Started
===============

[](#getting-started)

Schemas can be installed through composer.

```
composer require plasma/schemas

```

You first need to create a Plasma client and then create a `Repository` (which acts like a client) with the created client. Then you need to create your schema classes and the directory for these schema classes. You will need to register these directories to the Repository.

Directories build schemas from query results and interface with the repository for queries.

After that, each call onto the Repository `query` or `execute` methods will give you a dedicated `SchemaCollection` with the `Schema` instances. A call to `Repository::prepare` will give you, if successful, a wrapped `Statement` instance. The wrapper has the same purpose as the `Repository`.

```
$loop = \React\EventLoop\Factory::create();
$factory = new \Plasma\Drivers\MySQL\DriverFactory($loop, array());

$client = \Plasma\Client::create($factory, 'root:1234@localhost');
$repository = new \Plasma\Schemas\Repository($client);

/**
 * Our example table "users" consists of two columns:
 * - id ; auto incremented integer (length 12) primary
 * - name ; varchar(255) utf8mb4_generl_ci
 */
class Users extends \Plasma\Schemas\AbstractSchema {
    public $id;
    public $name;

    /**
     * Returns the schema definition.
     * @return \Plasma\Schemas\ColumnDefinitionInterface[]
     */
    static function getDefinition(): array {
        return array(
            // A generic column definition builder
            // solely for ease of use and does not
            // have to be used.
            // Any Plasma Column Definition
            // can be used.

            static::getColDefBuilder()
                ->name('id')
                ->type('INTEGER')
                ->length(12)
                ->autoIncrement()
                ->primary()
                ->getDefinition(),
            static::getColDefBuilder()
                ->name('name')
                ->type('VARCHAR')
                ->length(255)
                ->getDefinition()
        );
    }

    /**
     * Returns the name of the table.
     * @return string
     */
    static function getTableName(): string {
        return 'users';
    }

    /**
     * Returns the name of the identifier column (primary or unique), or null.
     * @return string|null
     */
    static function getIdentifierColumn(): ?string {
        return 'id';
    }
}

// null is the SQL grammar (see plasma/sql-common)
$builderA = new \Plasma\Schemas\SQLDirectory(Users::class, null);
$repository->registerDirectory('users', $builderA);

$repository->execute('SELECT * FROM `users`', array())
    ->done(function (\Plasma\Schemas\SchemaCollection $collection) {
        // Do something with the collection
    });

$loop->run();
```

Preloads
========

[](#preloads)

Schemas has a mechanism called Preloads.

Preloads are a way to load foreign references at the same time as a schema gets loaded, and let your schema be always filled with the foreign reference schema. How the preloads are exactly loaded depends on the Directory implementation.

Preloads are foreign targets with fetch mode `ALWAYS` and are automatically handled. Foreign target with fetch mode `LAZY` are not automatically loaded and need to be explicitely asked for by calling `resolveForeignTargets` on the schema.

Whether one uses one over the other fetch mode depends on the use case. It makes sense to only preload schemas you actually really always need.

Preloads are supported through the `ColumnDefinitionInterface`. Current implementations are the `ColumnDefinition` implementation and the `ColumnDefinitionBuilder`.

Documentation
=============

[](#documentation)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 83.3% 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

Every ~190 days

Total

5

Last Release

1901d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/85dbed21ee3f899a9fac2a46423ba9b5fc227ab189da1a54787e82e1222aa472?d=identicon)[gitneko](/maintainers/gitneko)

---

Top Contributors

[![gitneko](https://avatars.githubusercontent.com/u/67227083?v=4)](https://github.com/gitneko "gitneko (5 commits)")[![WyriHaximus](https://avatars.githubusercontent.com/u/147145?v=4)](https://github.com/WyriHaximus "WyriHaximus (1 commits)")

---

Tags

databsephpphp-libraryphp7plasmaschemas

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/plasma-schemas/health.svg)

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

PHPackages © 2026

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