All Projects → donjajo → Php Jsondb

donjajo / Php Jsondb

Licence: mit
A PHP Class that reads JSON file as a database. Use for sample DBs

Projects that are alternatives of or similar to Php Jsondb

Manticoresearch
Database for search
Stars: ✭ 610 (+535.42%)
Mutual labels:  json, database
Spimedb
EXPLORE & EDIT REALITY
Stars: ✭ 14 (-85.42%)
Mutual labels:  json, database
Sheetjs
📗 SheetJS Community Edition -- Spreadsheet Data Toolkit
Stars: ✭ 28,479 (+29565.63%)
Mutual labels:  json, database
Pickledb
pickleDB is an open source key-value store using Python's json module.
Stars: ✭ 549 (+471.88%)
Mutual labels:  json, database
Go Nulltype
Null friendly types
Stars: ✭ 79 (-17.71%)
Mutual labels:  json, database
Api
Our Database
Stars: ✭ 568 (+491.67%)
Mutual labels:  json, database
Jsonlite
A simple, self-contained, serverless, zero-configuration, json document store.
Stars: ✭ 819 (+753.13%)
Mutual labels:  json, database
Comuni Json
🇮🇹 Database JSON comuni italiani (2020) con informazioni ISTAT + CAP
Stars: ✭ 416 (+333.33%)
Mutual labels:  json, database
Ejdb
🏂 EJDB 2.0 — Embeddable JSON Database engine C library. Simple XPath like query language (JQL). Websockets / Android / iOS / React Native / Flutter / Java / Dart / Node.js bindings. Docker image.
Stars: ✭ 1,187 (+1136.46%)
Mutual labels:  json, database
Avocado
Strongly-typed MongoDB driver for Rust
Stars: ✭ 70 (-27.08%)
Mutual labels:  json, database
Sirdb
👨 a simple, git diffable JSON database on yer filesystem. By the power of NodeJS
Stars: ✭ 508 (+429.17%)
Mutual labels:  json, database
Summitdb
In-memory NoSQL database with ACID transactions, Raft consensus, and Redis API
Stars: ✭ 1,295 (+1248.96%)
Mutual labels:  json, database
Sleekdb
Pure PHP NoSQL database with no dependency. Flat file, JSON based document database.
Stars: ✭ 450 (+368.75%)
Mutual labels:  json, database
Filemasta
A search application to explore, discover and share online files
Stars: ✭ 571 (+494.79%)
Mutual labels:  json, database
Tinydb
TinyDB is a lightweight document oriented database optimized for your happiness :)
Stars: ✭ 4,713 (+4809.38%)
Mutual labels:  json, database
Nano Sql
Universal database layer for the client, server & mobile devices. It's like Lego for databases.
Stars: ✭ 717 (+646.88%)
Mutual labels:  json, database
Bigchaindb
Meet BigchainDB. The blockchain database.
Stars: ✭ 3,768 (+3825%)
Mutual labels:  json, database
Stormdb
🌩️ StormDB is a tiny, lightweight, 0 dependency, easy-to-use JSON-based database for NodeJS, the browser or Electron.
Stars: ✭ 406 (+322.92%)
Mutual labels:  json, database
Java Client Api
Java client for the MarkLogic enterprise NoSQL database
Stars: ✭ 52 (-45.83%)
Mutual labels:  json, database
Dbwebapi
(Migrated from CodePlex) DbWebApi is a .Net library that implement an entirely generic Web API (RESTful) for HTTP clients to call database (Oracle & SQL Server) stored procedures or functions in a managed way out-of-the-box without any configuration or coding.
Stars: ✭ 84 (-12.5%)
Mutual labels:  json, database

php-jsondb

A PHP Class that reads JSON file as a database. Use for sample DBs.

Usage

Install package composer require jajo/jsondb

Initialize

<?php 
use Jajo\JSONDB;
$json_db = new JSONDB( __DIR__ ); // Or passing the directory of your json files with no trailing slash, default is the current directory. E.g.  new JSONDB( '/var/www/html/json_files' )

Inserting

Insert into your new JSON file. Using users.json as example here

NB: Columns inserted first will be the only allowed column on other inserts

<?php
$json_db->insert( 'users.json', 
	[ 
		'name' => 'Thomas', 
		'state' => 'Nigeria', 
		'age' => 22 
	]
);

Get

Get back data, just like MySQL in PHP

All columns:
<?php
$users = $json_db->select( '*' )
	->from( 'users.json' )
	->get();
print_r( $users );
Custom Columns:
<?php 
$users = $json_db->select( 'name, state'  )
	->from( 'users.json' )
	->get();
print_r( $users );
	
Where Statement:

This WHERE works as AND Operator at the moment or OR

<?php 
$users = $json_db->select( 'name, state'  )
	->from( 'users.json' )
	->where( [ 'name' => 'Thomas' ] )
	->get();
print_r( $users );
	
// Defaults to Thomas OR Nigeria 
$users = $json_db->select( 'name, state'  )
	->from( 'users.json' )
	->where( [ 'name' => 'Thomas', 'state' => 'Nigeria' ] )
	->get();
print_r( $users );  
	
// Now is THOMAS AND Nigeria 
$users = $json_db->select( 'name, state'  )
	->from( 'users.json' )
	->where( [ 'name' => 'Thomas', 'state' => 'Nigeria' ], 'AND' )
	->get();
print_r( $users );  	
	
	
Where Statement with regex:

By passingJSONDB::regex to where statement, you can apply regex searching. It can be used for implementing LIKE or REGEXP_LIKE clause in SQL.

$users = $json_db->select( 'name, state' )
	->from( "users" )
	->where( array( "state" => JSONDB::regex( "/ria/" )), JSONDB::AND )
	->get();
print_r( $users );
// Outputs are rows which contains "ria" string in "state" column. 
Order By:

Thanks to Tarun Shanker for this feature. By passing the order_by() method, the result is sorted with 2 arguments of the column name and sort method - JSONDB::ASC and JSONDB::DESC

<?php 
$users = $json_db->select( 'name, state'  )
	->from( 'users.json' )
	->where( [ 'name' => 'Thomas' ] )
	->order_by( 'age', JSONDB::ASC )
	->get();
print_r( $users );

Updating Row

You can also update same JSON file with these methods

<?php 
$json_db->update( [ 'name' => 'Oji', 'age' => 10 ] )
	->from( 'users.json' )
	->where( [ 'name' => 'Thomas' ] )
	->trigger();
	

Without the where() method, it will update all rows

Deleting Row

<?php
$json_db->delete()
	->from( 'users.json' )
	->where( [ 'name' => 'Thomas' ] )
	->trigger();

Without the where() method, it will deletes all rows

Exporting to MySQL

You can export the JSON back to SQL file by using this method and providing an output

<?php 
$json_db->to_mysql( 'users.json', 'users.sql' );

Disable CREATE TABLE

<?php 
$json_db->to_mysql( 'users.json', 'users.sql', false );

Exporting to XML

Tarun Shanker also provided a feature to export data to an XML file

<?php 
if( $json_db->to_xml( 'users.json', 'users.xml' ) ) {
	echo 'Saved!';
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].