I saw many questions about json in stackoverflow. Most of them are unanswered or the basic idea is relaying on already existing techiniques.
I want to build json db to use it in a easy way as a query usage. Like SELECT a WHERE a = $var;
Please your suggestions.
Thanks in advance.
//sample jsondb
{
"name": "test",
"columns": ["a", "b"],
"rows": [[1, 2],
[3, 4]]
}
$var = 3;
//the aim is to use it easy as query usage
SELECT a WHERE a = $var;
//sample json object retrieved by PHP's json_encode()
stdClass Object
(
[name] => test
[columns] => Array
(
[0] => a
[1] => b
)
[rows] => Array
(
[0] => Array
(
[0] => 1
[1] => 2
)
[1] => Array
(
[0] => 3
[1] => 4
)
)
)
//have the column a
$cols = array_flip($obj->columns);
$col_a = $cols['a'];
//filter to a=$var
$rows_with_value_3 = array();
foreach($obj->rows as $index => $rowvalues){
foreach($rowvalues as $value){
if($value[$col_a] == $var)
$rows_with_value_3[$index] = $value[$col_a];
}
}
//below the query string build functions
....
You can add SculeJS to the above list. It does what you're looking for using a MongoDB style query interface, and it's written in JavaScript.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.