Last active
March 2, 2019 16:21
-
-
Save timothymarois/30b05530bbc9f4d6c325884c2a12062c to your computer and use it in GitHub Desktop.
Filebase (V2) Proposal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$config = []; | |
$database = new Database($config); | |
// DATABASE TABLES | |
// ----------------------------------- | |
// returns the config class | |
$database->config(); | |
// resets the config | |
$database->setConfig(array); | |
// get a single Table (return a Table Class) | |
$database->table('table_name'); | |
// get a Collection of Tables | |
// this should return an ARRAY of Table Classes | |
$database->tables(); | |
// get a array list of table names | |
$database->tableList(); | |
// deletes the database table directory (and all its contents) | |
$database->table('table_name')->delete(); | |
// empties the database table deleting all documents (keeping the table itself alive) | |
$database->table('table_name')->empty(); | |
// check if document exist | |
// return true/false | |
$database->table('table_name')->has('document_id'); | |
// DATABASE TABLE DOCUMENTS | |
// ----------------------------------- | |
// get a single document within the table | |
// Returns the Document:class regardless if the document was found. | |
// If document not found, return an empty document class | |
$document = $database->table('table_name')->get('document_id'); | |
// edit and save the document | |
// if the document does not exist, create it | |
$document->name = 'Tim'; | |
$document->save(); | |
// replace all document data ($data array) | |
$document->set(array $data); | |
// delete the document | |
$document->delete(); | |
// create/insert new document ($data array) | |
$database->table('table_name')->insert('document_id', $data); | |
// rename the document (updates the document file name etc) | |
$document->rename('document_id'); | |
// DATABASE TABLE QUERY DOCUMENTS | |
// ----------------------------------- | |
// multiple where statements (array) status = enabled and tag = php (returning a Collection of DOCUMENTS) | |
$documents = $database->table('table_name')->where([ | |
'status'=>'enabled', | |
'tag' => 'php' | |
])->get(); | |
// getting the first item of a query (Collection -> first()) | |
$document = $database->table('table_name')->where(['name'=>'Tim'])->first(); | |
// using the quick where method (save as the above) | |
$document = $database->table('table_name')->whereName('Tim')->first(); | |
// using where operators | |
$documents = $database->table('table_name')->where('email','LIKE','gmail')->get(); | |
// using order by and limit within query | |
$database->table('table_name') | |
->where('email','LIKE','gmail') | |
->orderBy('name','ASC') | |
->limit(5) | |
->get(); | |
// ability to use where (closure) to run more advanced query statements | |
// WHERE status = 'enabled' AND (email LIKE '%gmail.com%' OR email LIKE '%yahoo.com%' OR ) | |
$database->table('table_name') | |
->whereStatus('enabled') | |
->where(function($query){ | |
$query->where('email','LIKE','gmail.com'); | |
$query->orWhere('email','LIKE','yahoo.com'); | |
}) | |
->get(); | |
// ability to delete all documents listed in results | |
$database->table('table_name')->where('email','LIKE','gmail')->delete(); | |
// DATABASE BACKUPS | |
// | |
// LETS THIS FEATURE LATER | |
// ----------------------------------- | |
// access the database class | |
$database->backup(); | |
// get a Collection of backups | |
$database->backup()->get(); | |
// access the database class | |
$database->backup()->create(); | |
// rollback the backup (number for 1 = last) | |
$database->backup()->restore($number); | |
// delete backup (number of backup) | |
$database->backup()->delete($number); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment