porebskk/simple-php-document-store
Composer 安装命令:
composer require porebskk/simple-php-document-store
包简介
README 文档
README
SimplePhpDocumentStore is a simple document store (fancy words for storing php arrays) that is running sql under the hood. It also provides a query component using paths extracted from the document. The querying part is solved by doing extra lifting when the documents are stored in the database (storing all unique paths as separate values).
Installation
composer require porebskk/simple-php-document-store
Features
- A variety of database platforms are supported via DBAL
- JSON-Path Query Builder
Usage
Initialization
//Setting up the DbalAdapter, we are using here Sqlite in memory mode //requires the sqlite extension to be enabled in the used php.ini file $connectionParams = ['url' => 'sqlite:///:memory:']; $conn = DriverManager::getConnection($connectionParams); $conn->exec('PRAGMA foreign_keys = ON'); $dbalAdapter = new DbalAdapter($conn); //this is only required once for persistence storages $dbalAdapter->initDataStructure();
Storage
$document = [ 'person' => [ 'head' => [ 'nose' => 'big', 'eyes' => 'blue', ], ], ]; $documentId = $dbalAdapter->store($document);
Querying (by ID)
$documentId = $dbalAdapter->store($document); $document = $dbalAdapter->searchById($documentId);
Querying (with a QueryObject)
$query = new Query(); //Finding document where the JSON Path "person.head.eyes" is either red or orange //Allowed operators depend on the adapter implementation //for DBAL see the ExpressionBuilder::* constants $query->whereAnd( (new OrStatement())->add( new WhereStatement('person.head.eyes', '=', 'red'), new WhereStatement('person.head.eyes', '=', 'orange') ) ); $documents = $dbalAdapter->searchByQuery($query); //It is possible to wrap AND/OR Statement as deep as possible $query->whereAnd( (new OrStatement())->add( new WhereStatement('person.head.eyes', '=', 'blue'), (new AndStatement())->add( new WhereStatement('person.head.eyes', '=', 'orange'), new WhereStatement('person.character.crazy', '=', 'yes') ) ), new WhereStatement('person.feet', '=', 'big') );
Updating a document
$dbalAdapter->update($documentId, $updatedDocument);
Limit the amount of returned documents
$query = (new Query())->limit(5); $maximumOf5Documents = $dbalAdapter->searchByQuery($query);
Advanced Usage
Storing documents with array data and querying them:
$document = [ 'friends' => [ ['person' => ['name' => 'Bob', 'age' => 26]], ['person' => ['name' => 'Alice', 'age' => 25]], ], ]; $dbalAdapter->store($document); //Following paths will be extracted from the array: //'friends.person.name' => 'Bob', //'friends.person.age' => 26 //'friends.person.name' => 'Alice' //'friends.person.age' => 25 //Now we query the data $query = new Query(); $query->whereAnd( new WhereStatement('friends.person.age', '<', '30') ); $documents = $dbalAdapter->searchByQuery($query);
porebskk/simple-php-document-store 适用场景与选型建议
porebskk/simple-php-document-store 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10 次下载、GitHub Stars 达 1, 最近一次更新时间为 2018 年 06 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 porebskk/simple-php-document-store 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 porebskk/simple-php-document-store 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 10
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-06-17