daniloromka/eav
Composer 安装命令:
composer require daniloromka/eav
包简介
EAV model using PostgreSQL jsonb type
关键字:
README 文档
README
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: https://coussej.github.io/2016/01/14/Replacing-EAV-with-JSONB-in-PostgreSQL/
Getting started
1. Basis
1.1. 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
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
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.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
You can use your migration mechanism to pull changes from the database after creating the EAV model tables.
Alternative implementation
Alternative is manual creating your migration with SQL-queries which is in the src/Migration/Setup*.php files.
daniloromka/eav 适用场景与选型建议
daniloromka/eav 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 2, 最近一次更新时间为 2024 年 11 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「db」 「postgresql」 「model」 「attribute」 「eav」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 daniloromka/eav 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 daniloromka/eav 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 daniloromka/eav 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
SilverStripe now has tentative support for PostgreSQL ('Postgres')
Dibi is Database Abstraction Library for PHP
Store your language lines in the database, yaml or other sources
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Interfaces for web resource models and services to retrieve and create them
A PSR-7 compatible library for making CRUD API endpoints
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-11-16