ronolo/json-store 问题修复 & 功能扩展

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

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

ronolo/json-store

Composer 安装命令:

composer require ronolo/json-store

包简介

A lightweight JSON document store, which can be queried like a NoSQL database.

README 文档

README

A document store which uses any type of filesystem to store documents as JSON. It uses https://flysystem.thephpleague.com/ to abstract the storage space.

As by definition a store acts like ONE table in a database. You can put everything into one store or have many stores for different JSON objects.

It uses a NoSQL like query system for the documents and aims to use very low memory footprint (aka not loading all documents into memory to process them).

Note: There is a ronolo/json-database package, which uses the json-store and extends it with document relations (foreign keys) and query result caching.

Usage

First create a Config object.

Then specify the adapter which shall be used to actually store the JSON files to a disc/cloud/memory/zip. See https://github.com/thephpleague/flysystem to find the one which fits your needs. You have to init the adapter with the correct parameters.

// First create the config object
$config = new Store\Config();
// Set the the adapter
$config->setAdapter(new Local('some/path/persons'));
// Secondly create the JsonDB
$store = new Store($config);

The store is now ready. We can now store, read, delete and update documents. As a very basic usage, we can read every document back by ID.

Note: Update is always an update of the whole object. It is not possible to update single fields via store command.

As a speed bonus the store keeps all document IDs in an index file, which will be loaded on store construct. Another speed bonus would be to use the caching and speedup adapters found on the https://flysystem.thephpleague.com/v1/docs/advanced/caching/ page.

$document = file_get_contents('file/with/json/object.json');
// store a document
$id = $store->put($document);
// read a document
$document = $store->read($id);
// update document
$document->foobar = "Heinz";
$store->put($document);
// remove document
$store->remove($id); 

It is also possible to query documents in a CouchDB like fashion from the store.

$query = new Store\Query($store);
$result = $query->find([
    "name" => "Bernd"
]);

// An iterator can be used to fetch one by one all documents

foreach ($result as $id => $document) {
    ; // do something with the document
}

There are the following conditions implemented:

[
    '$eq' => 'isEqual',
    '$neq' => 'isNotEqual',
    '$gt' => 'isGreaterThan',
    '$gte' => 'isGreaterThanOrEqual',
    '$lt' => 'isLessThan',
    '$lte' => 'isLessThanOrEqual',
    '$in'    => 'isIn',
    '$nin' => 'isNotIn',
    '$null' => 'isNull',
    '$n' => 'isNull',
    '$notnull' => 'isNotNull',
    '$nn' => 'isNotNull',
    '$contains' => 'contains',
    '$c' => 'contains',
    '$ne' => 'isNotEmpty',
    '$e' => 'isEmpty',
    '$regex' => 'isRegExMatch',
]

Examples can be found in the subdirectories of tests/src/query.

A few examples from there:

// SELECT * FROM store WHERE age = 20 OR age = 30 OR age = 40;
$query = new Store\Query($store);
$result = $query
    ->find([
        ["age" => 20],
        ["age" => 30],
        ["age" => 40]
    ])
    ->execute()
;

// SELECT index, guid FROM store ORDER BY index ASC LIMIT 60;
$query = new Store\Query($store);
$result = $query
    ->find([])
    ->fields(["index", "guid"])
    ->sort("index", "asc")
    ->limit(60)
    ->execute()
;

// SELECT * FROM store WHERE age = 20 AND phone = '12345' OR age = 40;
$query = new Store\Query($store);
$result = $query
    ->find([
        '$or' => [
            [
                "age" => [
                    '$eq' => 20,
                ],
                "phone" => [
                    '$eq' => "12345",
                ]
            ],
            [
                "age" => [
                    '$eq' => 40
                ]
            ]
        ]
    ])
    ->execute()
;

Goals

  • No real database needed like SqlLite, Mysql, MongoDB, CouchDB ...)
  • PHP 7.2+
  • Document Store aka NoSQL
  • JSON as format of storage
  • (very) low memory usage even for huge results
  • NoSQL like query syntax (CouchDB style)
  • Abstract data location via https://flysystem.thephpleague.com/

Limitations

  • Any limitation the underlying flysystem adapter has
  • If the creation of an unique ID fails, there will be an exception

ronolo/json-store 适用场景与选型建议

ronolo/json-store 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14 次下载、GitHub Stars 达 2, 最近一次更新时间为 2020 年 10 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「nosql」 「json」 「file」 「db」 「document」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 ronolo/json-store 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ronolo/json-store 我们能提供哪些服务?
定制开发 / 二次开发

基于 ronolo/json-store 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-10-02