sevens / jsondb
简单的 PHP 测试 JSON 数据库;适用于开发模式测试
v0.1.0
2021-09-21 09:56 UTC
Requires
- php: >=8.0.0
- sevens/vars: ^1.1.0
Requires (Dev)
- phpunit/phpunit: ^9.4.2
This package is auto-updated.
Last update: 2024-09-21 16:48:51 UTC
README
=> Simple Php Test JSON Database; useful for development mode
=> Seven JsonDB is developed by Elisha Temiloluwa a.k.a TemmyScope
=> Seven JsonDB is a library that comes with a Validation Class,
Arrays Manipulation Class and Strings Generation, Encoding, Sanitization & Manipulation Class
安装
composer require sevens/jsondb
使用方法:Seven\JsonDB\JsonDB HOW-TO
完全单元测试
- Valid Input Sample
$data = [ 'name' => 'Random 1', 'age' => 24, 'password' => 'gHAST_V43SS', 'nickname' => 'dick & harry' ];
- Initialization
use Seven\JsonDB\JsonDB; $db = JsonDB::init($directory, $database); $table = JsonDB::init($directory, $database, $tblName); //OR $table = $db->setTable($tblName);
- Make database
*** 使用此语法创建数据库 ***
use Seven\JsonDB\JsonDB; $newDB = JsonDB::make(string $directory, $database): string; #returns database name if successfully created
- Create Table
*** 使用此语法创建表 ***
$schema = [ 'name', 'email', 'password' ]; $table->createTable($table, $schema); //To use the 'save' method, you need to use a schema when creating a table
注意:id、createdAt 和 updatedAt 是自动生成的字段,但您也可以自己生成它们
- List all databases
*** 使用此语法列出所有可用的数据库 ***
use Seven\JsonDB\JsonDB; $newDB = JsonDB::list(string $directory): array; #returns an array of databases found
- Count number of databases
*** 使用此语法统计可用的数据库数量 ***
use Seven\JsonDB\JsonDB; $newDB = JsonDB::count(string $directory): int; #returns number of databases found
- Delete database
*** 使用此语法删除数据库 ***
use Seven\JsonDB\JsonDB; $newDB = JsonDB::delete($directory, $db): bool; #returns true name if successfully deleted
- Empty a database; delete database content
*** 使用此语法从数据库中删除所有内容 ***
use Seven\JsonDB\JsonDB; $newDB = JsonDB::empty($directory, $db): void; #returns database name if successfully created
表操作
- Generate an Id
use Seven\JsonDB\Table; $table->generateId(Table::TYPE_STRING || Table::TYPE_INT); //default is Table::TYPE_STRING
- Get Last Insert Id
$table->lastInsertId();
- Save Data In the Table: Only works on tables that were created with schema
//$table->id = 1; $table->name = 'Elisha Temiloluwa'; $table->email = 'Elisha@gmail.com'; $table->password = hash('SHA256', 'password'); $table->save();
- Insert Data In the Table
$table->insert([ 'email' => 'sammy@hotmail.com', 'name' => 'Sam Orji', 'password' => hash('SHA256', 'passphr4s3'), ]);
- Find items in the table using certain conditions
$table->find([ 'email' => 'Elisha@gmail.com' ], );
- Find items in the table using id
- Find items in the table using certain conditions
- Find items in the table using certain conditions