PHPackages                             daniloromka/eav - 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. daniloromka/eav

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

daniloromka/eav
===============

EAV model using PostgreSQL jsonb type

1.0.0(1y ago)20MITPHPPHP ^5.0 || ^7.0 || ^8.0

Since Nov 16Pushed 1y ago1 watchersCompare

[ Source](https://github.com/daniloromka/EAV)[ Packagist](https://packagist.org/packages/daniloromka/eav)[ RSS](/packages/daniloromka-eav/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

EAV - jsonb
===========

[](#eav---jsonb)

This is project is an implementation of the EAV (Entity-Attribute-Value) model based on PostgreSQL database using jsonb type.

This EAV-model combines the power of a relational database with the search speed of a non-relational database.

The idea was written here:

Getting started
---------------

[](#getting-started)

### 1. Basis

[](#1-basis)

#### 1.1. Creating the structure

[](#11-creating-the-structure)

Run this console command to create EAV model tables in the database (need use the correct DSN value to connect to the PostgreSQL database):

```
php setup.php "PDO_PGSQL_DSN=pgsql:host=localhost;port=5432;dbname=postgres;user=postgres;password=mypass"
```

Will be output:

> Successfully completed.

The result will be creating of 5 tables in your database with the prefix `eavjsonb_`:

```
eavjsonb_attribute
| id | name        |
| -- | ----------- |
| 1  | Attribute 1 |

```

```
eavjsonb_value
| id | attribute_id | name    |
| -- | ------------ | ------- |
| 1  | 1            | Value 1 |

```

```
eavjsonb_category
| id | name       |
| -- | ---------- |
| 1  | Category 1 |

```

```
eavjsonb_category_attribute
| id | attribute_id | category_id | is_diapason |
| -- | ------------ | ----------- | ----------- |
| 1  | 1            | 1           | false       |

```

```
eavjsonb_entity
| id | name     | category_id | attribute_values |
| -- | -------- | ----------- | ---------------- |
| 1  | Entity 1 | 1           | {"1": "Value 1"} |

```

Note: You can add PDO\_PGSQL\_DSN setting to your .env file (see .env.example file)

#### 1.2. Test data generation

[](#12-test-data-generation)

Test data is needed here. Test data can be generated by the following console command:

```
php generateTestData.php
```

Will be output:

> Estimated execution time: 15 min
>
> Successfully completed.

The result will be 10 million created entities with different attributes and values.

#### 1.3. Data selecting test

[](#13-data-selecting-test)

You can test of data selecting from the EAV model by running the console command:

```
php test.php
```

The test result can be as follows:

> Total records count: 10000000
>
> Filtered records count where {"1":"Value 1"}: 1
>
> Execution time: 4728.9 ms

### 2. Adding indexing

[](#2-adding-indexing)

2.1. Next, run this console command to adding indexing in the database:

```
php setup2.php
```

The result of execution will be the creation index for jsonb field:

> Estimated execution time: 18 min
>
> Successfully completed.

2.2. Then it can be tested again by running the console command:

```
php test.php
```

Now the test result will be as follows:

> Total records count: 10000000
>
> Filtered records count where {"1":"Value 1"}: 1
>
> Execution time: 0.8 ms

**This is a stunning result! This is less than 1 ms per 10 million records!**

Implementation
--------------

[](#implementation)

You can use your migration mechanism to pull changes from the database after creating the EAV model tables.

Alternative implementation
--------------------------

[](#alternative-implementation)

Alternative is manual creating your migration with SQL-queries which is in the src/Migration/Setup\*.php files.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

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

546d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/33fa28f6b53e9f826f083b9786f6604e0050f8f7349a225d0b4da59e53fe96a4?d=identicon)[daniloromka](/maintainers/daniloromka)

---

Top Contributors

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

---

Tags

attributedatabasedbeaventityfaceted-searchimplementationjson-indexingjsonbmodelpostgresqlstructuretablestest-datatest-data-generatorvaluedatabasepostgresqlmodeldbentitystructurevaluetablesimplementationattributejsonbfaceted searcheavtest datatest data generatorjson-indexing

### Embed Badge

![Health badge](/badges/daniloromka-eav/health.svg)

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

###  Alternatives

[amphp/postgres

Asynchronous PostgreSQL client for Amp.

110509.8k27](/packages/amphp-postgres)[davmixcool/php-dbcloud

Easily backup PostgreSql or MySql database to the cloud

111.5k](/packages/davmixcool-php-dbcloud)

PHPackages © 2026

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