PAX comes with a basic seeding class that provides the inital database design for your application prior to generating your database.
The seed data document can be found at
back >
db >
database.json
The seed schema document can be seen at
back >
db >
map.json
By default, the CRUD class is pointing to the seed database for querying
//Search Database
/api/crud/search/pages
//Get Row
api/crud/get/pages/1
//Save Row
/api/crud/save/pages/1
//Update Row
/api/crud/update/pages/1?pretty=1
//Delete Row
/api/crud/delete/pages/1?pretty=1
Simply update the database.json file to add or remove seeding data
back > db > database.json
{
"dbName":{
"pages":[
{
"id":"1",
"name":"home",
"description":"Welcome to my website",
"views":22
},
{
"id":"2",
"name":"about",
"description":"About us",
"views":44
}
]
}
}
Update the map.json file to add or remove database schema
back > db > map.json
{
"dbName":{
"pages":{
"id":{"type":"key"},
"name":{"type":"string"},
"description":{"type":"string"},
"views":{"type":"int"}
}
}
}
The PAX db.php class has a seeding method that will delete and re-index your MYSQL database. And the PAX crud.php class seeding method will use the json files to re-index automatically.
back > app > lib > db.php
back > app > lib > crud.php
*Warning: This will erase the database and reset the scheme and inject new data.
$data = [
"DB_NAME"=>[
"users"=>[
[
"id"=>1,
"name"=>"John Doe"
]
]
]
];
$map = [
"DB_NAME"=>[
"users"=>[
"id"=>["type"=>"key"],
"email"=>["type"=>"string"]
]
]
];
$app->get("db")->seed("DB_NAME", $data, $map);
First set the constants in the config file for your MYSQL configuration.
back > sys > config.php
define('DB_CLASS', "db");
define('DB_SERVER', "localhost");
define('DB_PORT', "9200");
define('DB_NAME', 'dbName');
define('DB_USER', 'root');
define('DB_PASS', 'root');
Next run the seed method
*Warning: This will erase the database and reset the scheme and inject new data.
$app->get("crud")->seed();