PHPackages                             sinevia/php-library-schemaless - 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. sinevia/php-library-schemaless

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

sinevia/php-library-schemaless
==============================

PHP Library Schemaless

v1.0.0(7y ago)2841proprietaryPHP

Since Jul 28Pushed 7y ago1 watchersCompare

[ Source](https://github.com/Sinevia/php-library-schemaless)[ Packagist](https://packagist.org/packages/sinevia/php-library-schemaless)[ Docs](http://github.com/sinevia/php-library-schemaless)[ RSS](/packages/sinevia-php-library-schemaless/feed)WikiDiscussions master Synced today

READMEChangelog (5)DependenciesVersions (6)Used By (0)

Schemaless
==========

[](#schemaless)

[![Latest Stable Version](https://camo.githubusercontent.com/cf477f79d344736255a7c9ca17c9dded761a196d6dd6a9b569addec920df3135/68747470733a2f2f706f7365722e707567782e6f72672f73696e657669612f7068702d6c6962726172792d736368656d616c6573732f762f737461626c65)](https://packagist.org/packages/sinevia/php-library-schemaless)[![Total Downloads](https://camo.githubusercontent.com/bb23bf4e4bf3498c3e5d6e4530e22235efca422e252c09bfa19afb6229abc1eb/68747470733a2f2f706f7365722e707567782e6f72672f73696e657669612f7068702d6c6962726172792d736368656d616c6573732f646f776e6c6f616473)](https://packagist.org/packages/sinevia/php-library-schemaless)[![Latest Unstable Version](https://camo.githubusercontent.com/8d62a6388cc185b8b5a5e93584ed73b3916d1d9ccd24604859ede4f32fefce3c/68747470733a2f2f706f7365722e707567782e6f72672f73696e657669612f7068702d6c6962726172792d736368656d616c6573732f762f756e737461626c65)](https://packagist.org/packages/sinevia/php-library-schemaless)[![License](https://camo.githubusercontent.com/c1cd7fe269b5e2a867cdddc59995b55101451e53aea7cd37b80c52fb8a58f2c4/68747470733a2f2f706f7365722e707567782e6f72672f73696e657669612f7068702d6c6962726172792d736368656d616c6573732f6c6963656e7365)](https://packagist.org/packages/sinevia/php-library-schemaless)[![Monthly Downloads](https://camo.githubusercontent.com/deecd63f5638848952ddf41236965249272644293d11dc9f26a23862bff000cb/68747470733a2f2f706f7365722e707567782e6f72672f73696e657669612f7068702d6c6962726172792d736368656d616c6573732f642f6d6f6e74686c79)](https://packagist.org/packages/sinevia/php-library-schemaless)[![Daily Downloads](https://camo.githubusercontent.com/9b485e118ec8dfcd8c3dc43b6758045f0705a10310fc5606fdea2dca8b3ef3ce/68747470733a2f2f706f7365722e707567782e6f72672f73696e657669612f7068702d6c6962726172792d736368656d616c6573732f642f6461696c79)](https://packagist.org/packages/sinevia/php-library-schemaless)[![composer.lock](https://camo.githubusercontent.com/8e9641ddecbbc2148220f36a1a725b2b129fbf38370aef673ba14430cdaf1efd/68747470733a2f2f706f7365722e707567782e6f72672f73696e657669612f7068702d6c6962726172792d736368656d616c6573732f636f6d706f7365726c6f636b)](https://packagist.org/packages/sinevia/php-library-schemaless)

A streamlined entity-attribute (EA) implementation for PHP. This package is designed for quick plug and play "schemaless" prototyping. To achieve this the package uses only two database tables unlike the standard EAV (which uses at least three tables).

Install
-------

[](#install)

Using composer

```
composer require sinevia/php-library-schemaless
```

Create storage tables

```
\Sinevia\Schemaless::createTables();
```

Uninstall
---------

[](#uninstall)

Delete storage tables

```
\Sinevia\Schemaless::deleteTables();
```

How to Use?
-----------

[](#how-to-use)

1. Creating new entities

```
// 1. Create new person
$person = \Sinevia\Schemaless::createEntity([
    'Type' => 'Person',
    'Title' => 'Peter Pan'
]);

// 2. Check if successful
if (is_null($person)) {
    die('Entity failed to be created');
} else {
    echo 'New entity created with Id '.$person['Id']);
    var_dump($person);
}

// 3. Create new person with attributes
$person = \Sinevia\Schemaless::createEntity([
    'Type' => 'Person',
    'Title' => 'Peter Pan',
        ], [
    'FirstName' => 'Peter',
    'LastName' => 'Pan',
    'AddressLine1' => '23 Kings Way',
    'AddressLine2' => 'Wolves Den',
    'Postcode' => 'WWW 123 NET',
    'Country' => 'WW',
]);

// 4. Check if successful
if (is_null($person)) {
    die('Entity failed to be created');
} else {
    echo 'New entity created with Id '.$person['Id']);
    var_dump($person);
}
```

2. Set attributes

```
// 1. Add attributes individually
\Sinevia\Schemaless::setAttribute($personId, 'AddressLine1', '45 Queens Road');
\Sinevia\Schemaless::setAttribute($personId, 'AddressLine2', 'Foxes Layer');

// 2. Add many attributes at once
\Sinevia\Schemaless::setAttributes($personId, [
    'AddressLine1' => '122 Shepherds Close',
    'AddressLine2' => 'Cows Barn',
]);
```

3. Get entities

```
// 1. Retrieve entity by Id
$person = \Sinevia\Schemaless::getEntity($personId);
var_dump($person);

// 1. Retrieve entity by Id with Attributes
$person = \Sinevia\Schemaless::getEntity($personId, ['withAttributes' => true]);
var_dump($person);

// 2. Retrieve entities by search
$people = \Sinevia\Schemaless::getEntities([
    'Type' => 'Person',
    'IsActive' => 'Yes',
    'limitFrom' => 0,
    'limitTo' => 2,
    // Advanced querying
    'wheres' => [
        ['CreatedAt', '>', '2018-07-27 22:24:10'],
        ['CreatedAt', '
