Skip to content

Instantly share code, notes, and snippets.

@faryar76
Forked from timothymarois/filebase.php
Last active March 2, 2019 16:43
Show Gist options
  • Save faryar76/6dcbe1da8536c5e981acd88b434e67b3 to your computer and use it in GitHub Desktop.
Save faryar76/6dcbe1da8536c5e981acd88b434e67b3 to your computer and use it in GitHub Desktop.
Filebase (V2) Proposal
<?php
$config = [];
$database = new Database($config);
// DATABASE TABLES
// -----------------------------------
// returns the config class
$database->config();
// change configs in run time
$database->path='new path';
// get a single Table (return a Table Class) if not exist will create
$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')->find(0);
// return bool if not found
$document = $database->table('table_name')->findOrFail(0);
// will return all
$document = $database->table('table_name')->get();
// edit and save the document
// if the document does not exist, create
$document = $database->table('table_name')->find(0);
$document->name = 'Tim';
$document->save();
// update just new values ($data array)
$document->update(array $data);
// delete the document
$document->delete();
// create/insert new document ($data array)
$database->table('table_name')->create($data);
// DATABASE TABLE QUERY DOCUMENTS
// -----------------------------------
// multiple where statements (array) status = enabled and tag = php (returning a Collection of DOCUMENTS)
// multi arrays inside single array
$documents = $database->table('table_name')->where([
['status','==','enabled'],
['name','==','test'],
])->get();
// also many multi array without single array
$documents = $database->table('table_name')->where(
['status','==','enabled'],
['name','==','test']
)->get();
also this methods working in orwhere
// 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