- Simple PHP JSON database for development/testing workflows.
- Seven JsonDB is developed by Elisha Temiloluwa a.k.a TemmyScope.
- Built on the Seven Vars utilities for arrays and strings.
- PHP 8.4+
- Composer
composer require sevens/jsondbCompletely unit tested
- 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 this syntax to create a database ***
use Seven\JsonDB\JsonDB;
$newDB = JsonDB::make(string $directory, string $database): bool;
#returns true if successfully created- Create Table
*** use this syntax to create a table ***
$schema = [
'name', 'email', 'password'
];
$table->createTable($table, $schema);
//To use the 'save' method, you need to use a schema when creating a tableNote: id, createdAt and updatedAt are auto-generated fields but you can generate them as well
- List all databases
*** Use this syntax to list all available databases ***
use Seven\JsonDB\JsonDB;
$newDB = JsonDB::list(string $directory): array;
#returns an array of databases found- Count number of databases
*** Use this syntax to count number of available database ***
use Seven\JsonDB\JsonDB;
$newDB = JsonDB::count(string $directory): int;
#returns number of databases found- Delete database
*** Use this syntax to delete a database ***
use Seven\JsonDB\JsonDB;
$newDB = JsonDB::delete($directory, $db): bool;
#returns true name if successfully deleted- Empty a database; delete database content
*** Use this syntax to delete all contents from a database ***
use Seven\JsonDB\JsonDB;
$newDB = JsonDB::empty($directory, $db): bool;
#returns true on success- 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
$table->findById('38a92f92b1268c64');- Find the first or last matching item
$table->first(['email' => 'Elisha@gmail.com']);
$table->last(['email' => 'Elisha@gmail.com']);composer install
./vendor/bin/phpunit