承接 fernandothedev/jsonsql 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

fernandothedev/jsonsql

最新稳定版本:0.1.14

Composer 安装命令:

composer create-project fernandothedev/jsonsql

包简介

Melhor coisa pra manipular json com php.

README 文档

README

PHP Code style License

JsonSQL is a way to use json as a database in testing or really small projects. No IO control, no advanced logging system or anything like that. If you want to use it, use it. You don't need to configure anything and it's super simple to use.

I believe that json is not good, and I believe that php is not ideal, there are problems like 2 requests and changing the file at the same time. Let's say someone changes the file and 0.01s later another person changes other information, the file has not yet been saved, I mean, if it is too wide it will certainly not have been saved in that time and will soon corrupt the data edited at 0.01s. Therefore, only use it if it is really for testing, or something very specific.

Instalation

With composer install with the command:

composer require fernandothedev/jsonsql

Usage

The target json file must have at least open braces.

file.json: {}

Class

Use the class using the Fernando\\JsonSQL namespace:

<?php

use Fernando\\JsonSQL;

require_once __DIR__ . '/path/from/autoload.php';

$file = __DIR__ . '/path/from/file.json';

$jsonsql = new JsonSQL($file);

Insert

// return true
$jsonsql->insert(key: 'fernandothedev', array: [
    'name' => 'Fernando',
    'age' => 16,
    'love' => 'php'
]);

Select

// return false [ user not exists ]
var_dump($jsonsql->select(key: 'fernando'));

// return array [ user exists ]
print_r($jsonsql->select(key: 'fernandothedev'));

// return array<T>
var_dump($jsonsql->select(key: 'fernandothedev', array: [
    'name'
]));

Update

// return true { update [ unic user ] }
$jsonsql->update(key: 'fernandothedev', array: [
    'love' => 'water'
]);

sleep(seconds: 3);

// retur true { update [ all users ] }
var_dump($jsonsql->update(array: [
    'love' => 'money'
]));

Delete

// return false [ user not exists ]
$jsonsql->delete(key: 'fernando2');

// return false [ key not exists ]
$jsonsql->delete(key: 'fernando', array: [
    'key-dont-exists'
]);

// return true [ user deleted ]
$jsonsql->delete(key: 'fulano');

// return true { user [ key deleted ] }
$jsonsql->delete(key: 'fernandothedev', array: [
    'love'
]);

Structure

Always leave the columns the same, if a user has name, age and other columns, all other users must have them too, to avoid errors.

{
    "my-user": {
        "key": "value"
    },
    "my-other-user": {
        "key": "value"
    }
}

Bye!

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-10-19