mhujer/json-simple-db

像操作简单数据库一样操作 JSON 文件

1.1.1 2015-11-26 18:30 UTC

This package is auto-updated.

Last update: 2024-08-29 04:45:45 UTC


README

Latest Stable Version Total Downloads License Coverage Status

对于一个生成静态 HTML 的项目,我需要一个数据源,所以我创建了这样一个简单的库来存储 JSON 中的数据。它仅适用于单个客户端的 CLI 使用,不适用于网站!

使用方法

  1. 使用 composer require mhujer/json-simple-db 安装最新版本
  2. 根据以下示例使用,并查看文档注释
<?php
require_once 'vendor/autoload.php';

//initialize DB
$db = new JsonSimpleDb\Db('./foo');

//initialize table
if (!$db->tableExists('mytable')) {
    $db->createTable('mytable');
}
$table = $db->getTable('mytable');

//get items count
$table->count(); //0

//insert into table
$table->insert([
    'id' => '1',
    'name' => 'foo',
]);

//find by array - like in MongoDB
$items = $table->find(['id' => '1']);
/*
array(1) {
  [0] =>
  array(2) {
    'id' =>
    string(1) "1"
    'name' =>
    string(3) "foo"
  }
}
 */

//update record
$table->update(['id' => '1'], ['name' => 'boo']);

//delete record
$table->delete(['id' => '1']);

//persist the data to file - don't forget this :-)
$table->persist();

要求

JSON SimpleDB 与 PHP 5.6 或 PHP 7 兼容。

提交错误和功能请求

错误和功能请求在 GitHub 上跟踪

作者

Martin Hujer - mhujer@gmail.com - http://www.martinhujer.cz

更新日志

1.1.1 (2015-11-26)

  • 存储的 JSON 格式化输出

1.1.0 (2015-11-26)

  • 添加了删除记录的功能

1.0.1 (2015-11-17)

  • 比较器进行严格匹配

1.0.0 (2015-11-14)

  • 初始发布