File tree Expand file tree Collapse file tree 2 files changed +24
-37
lines changed Expand file tree Collapse file tree 2 files changed +24
-37
lines changed Original file line number Diff line number Diff line change 1
1
## json-db
2
2
- JSON DB for APIs Testing for Your Minimalist Project
3
3
4
- ## Installation
4
+ ### Example
5
+ Full example of json db
6
+ ``` php
7
+ <?
5
8
6
- ``` bash
7
- git clone https://github.com/codewithsushil/json-db.git
8
- cd json-db
9
- php -S localhost:8888
10
- curl http://localhost:8888
11
- ```
9
+ require "vendor/autoload.php";
12
10
13
- ## setup
14
- ``` php
15
- $db = new jsondb(__dir__);
11
+ use App\JSONDatabase;
16
12
17
- ```
13
+ $path = 'data/users.json';
18
14
19
- ## Post
20
- ``` php
21
- $db->post("users", [
15
+ $db = new JSONDatabase($path);
16
+
17
+ $data = [
22
18
'id' => 1,
23
- 'name' => 'jhon ',
24
- 'email ' => 'jhon@example.com' ,
25
- 'create_at ' => '20:34:05:05:2025'
26
- ]);
27
- ```
19
+ 'name' => 'Sushil ',
20
+ 'age ' => 23 ,
21
+ 'dev ' => true,
22
+ 'lang' => ['php','javascript','sql']
23
+ ];
28
24
29
- ## Get
30
- ``` php
31
- $db->get("users", true); // all data
32
- $db->get("users", $id); // single data
33
- ```
25
+ // post data
26
+ $db->write($data);
34
27
35
- ## update
36
- ``` php
37
- $db->update("users",$id, [
38
- 'name' => 'lily'
39
- ])
40
- ```
28
+ // fetch data
29
+ $result = $db->read();
41
30
42
- ## delete
43
- ``` php
44
- $db->delete("users", $id);
45
- ```
31
+ echo "<pre >";
32
+ print_r($result);
33
+ echo "</pre >";
46
34
47
- ## search or like?
48
- ```
49
- $db->search('users','jhon');
50
35
```
36
+
Original file line number Diff line number Diff line change 1
1
<?php
2
2
namespace App ;
3
+ use Exception ;
3
4
4
5
class JSONDatabase {
5
6
private $ filePath ;
You can’t perform that action at this time.
0 commit comments