porebskk/simple-php-document-store 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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);

统计信息

  • 总下载量: 10
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-06-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固