Answer the question
In order to leave comments, you need to log in
How to create a DB using json (json-server)?
I don’t know how to write $path when creating a database variable $jdb = new Jsondb($path);
$path - the path from the root to the folder where the files will be stored. Default $path = $_SERVER["DOCUMENT_ROOT"].'/jdb/'.
I also do not understand what kind of keys:
Create. Creating a table. $jdb->create($table, $keys);
$keys - array of table keys and their characteristics. Auto_increment and default are supported.
Example:
$keys = Array(
'id'=>Array('auto_increment'),
'title'=>Array('default'=>'habrahabr'),
'posts',
'userId'
);
$jdb->create('habr', $keys);
Answer the question
In order to leave comments, you need to log in
the answer was found:
it was just necessary to write in the db.json file like this:
"posts": [
{ "id": 1, "title": "json-server", "author": "typicode" }
],
"comments": [
{ "id": 1, "body": "some comment", "postId": 1 }
],
"profile": { "name": "typicode" }
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question