定制 hanneskod/yaysondb 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

hanneskod/yaysondb

Composer 安装命令:

composer require hanneskod/yaysondb

包简介

Flat file db storing data as json arrays

README 文档

README

Packagist Version Build Status Quality Score

Flat file db in pure php.

Why?

Partly as a learning exercise, partly since I needed a simple and PHP only DB for some cli scripts.

Features

Installation

composer require hanneskod/yaysondb

Usage

Setup

Yaysondb works as a handler for multiple collections.

use hanneskod\yaysondb\Yaysondb;
use hanneskod\yaysondb\Engine\FlysystemEngine;
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Local;

$db = new Yaysondb([
    'table' => new FlysystemEngine(
        'data.json',
        new Filesystem(new Local('path-to-files'))
    )
]);

Access collection through property or collection()

$db->table === $db->collection('table');

Create

$db->table->insert(['name' => 'foobar']);

Transactions

Commit or rollback changes using commit(), reset() and inTransaction()

$db->table->commit();

Concurrency protection

Yaysondb supports limited concurrency protection when using the flysystem engine. A hash of the backend file is calculated at each read and any write action will fail if the hash has changed.

Read

Create search documents using the Operators class.

use hanneskod\yaysondb\Operators as y;

// Find all documents with an address in new york
$result = $db->table->find(
    y::doc([
        'address' => y::doc([
            'town' => y::regexp('/new york/i')
        ])
    ])
);

// The result set is filterable
foreach ($result->limit(2) as $id => $doc) {
    // iterate over the first 2 results
}

The search document

The following operators are available when creating search documents:

Operator Description
doc(array $query) Evaluate documents and nested subdocuments
not(Expr $e) Negate expression
exists() Use to assert that a document key exists
type($type) Check if operand is of php type
in(array $list) Check if operand is included in list
regexp($reg) Check if operand matches regular expression
equals($op) Check if operands equals each other
same($op) Check if operands are the same
greaterThan($op) Check if supplied operand is greater than loaded operand
greaterThanOrEquals($op) Check if supplied operand is greater than or equals loaded operand
lessThan($op) Check if supplied operand is less than loaded operand
lessThanOrEquals($op) Check if supplied operand is less than or equals loaded operand
all(Expr ...$e) All contained expressions must evaluate to true
atLeastOne(Expr ...$e) At least one contained expressions must evaluate to true
exactly($c, Expr ...$e) Match exact number of contained expressions evaluating to true
none(Expr ...$e) No contained expressions are allowed evaluate to true
one(Expr ...$ex) Exactly one contained expressions must evaluate to true
listAll(Expr $e) Expression must evaluate to true for each list item
listAtLeastOne(Expr $e) Expression must evaluate to true for at least one list item
listExactly($c, Expr $e) Expression must evaluate to true for exact numer of items in list
listNone(Expr $e) Expression is not allowed to evaluate to true for any list item
listOne(Expr $e) Expression must evaluate to true for exactly one list item

Update

Collection::update() takes two arguments. A search document and an array of values. Documents matching the search document are updated with the supplied values.

Delete

Collection::delete() takes a search document as sole argument. Documents matching the search document are removed.

统计信息

  • 总下载量: 2.22k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 0
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: WTFPL
  • 更新时间: 2014-10-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固