· 7 years ago · Mar 03, 2019, 02:14 PM
1<?php
2
3
4$config = [];
5$database = new Database($config);
6
7
8// DATABASE TABLES
9// -----------------------------------
10
11// returns the config class
12$database->config();
13
14// resets the config
15$database->setConfig(array);
16
17// get a single Table (return a Table Class)
18$database->table('table_name');
19
20// get a Collection of Tables
21// this should return an ARRAY of Table Classes
22$database->tables();
23
24// get a array list of table names
25$database->tableList();
26
27// deletes the database table directory (and all its contents)
28$database->table('table_name')->delete();
29
30// empties the database table deleting all documents (keeping the table itself alive)
31$database->table('table_name')->empty();
32
33// check if document exist
34// return true/false
35$database->table('table_name')->has('document_id');
36
37
38// DATABASE TABLE DOCUMENTS
39// -----------------------------------
40
41// get a single document within the table
42// Returns the Document:class regardless if the document was found.
43// If document not found, return an empty document class
44$document = $database->table('table_name')->get('document_id');
45
46// edit and save the document
47// if the document does not exist, create it
48$document->name = 'Tim';
49$document->save();
50
51// replace all document data ($data array)
52$document->set(array $data);
53
54// delete the document
55$document->delete();
56
57// create/insert new document ($data array)
58$database->table('table_name')->insert('document_id', $data);
59
60// rename the document (updates the document file name etc)
61$document->rename('document_id');
62
63
64// DATABASE TABLE QUERY DOCUMENTS
65// -----------------------------------
66
67// multiple where statements (array) status = enabled and tag = php (returning a Collection of DOCUMENTS)
68$documents = $database->table('table_name')->where([
69 'status'=>'enabled',
70 'tag' => 'php'
71])->get();
72
73// getting the first item of a query (Collection -> first())
74$document = $database->table('table_name')->where(['name'=>'Tim'])->first();
75
76// using the quick where method (save as the above)
77$document = $database->table('table_name')->whereName('Tim')->first();
78
79// using where operators
80$documents = $database->table('table_name')->where('email','LIKE','gmail')->get();
81
82// using order by and limit within query
83$database->table('table_name')
84 ->where('email','LIKE','gmail')
85 ->orderBy('name','ASC')
86 ->limit(5)
87 ->get();
88
89
90 // ability to use where (closure) to run more advanced query statements
91 // WHERE status = 'enabled' AND (email LIKE '%gmail.com%' OR email LIKE '%yahoo.com%' OR )
92 $database->table('table_name')
93 ->whereStatus('enabled')
94 ->where(function($query){
95 $query->where('email','LIKE','gmail.com');
96 $query->orWhere('email','LIKE','yahoo.com');
97 })
98 ->get();
99
100
101// ability to delete all documents listed in results
102$database->table('table_name')->where('email','LIKE','gmail')->delete();
103
104
105
106
107// DATABASE BACKUPS
108//
109// LETS THIS FEATURE LATER
110// -----------------------------------
111
112// access the database class
113$database->backup();
114
115// get a Collection of backups
116$database->backup()->get();
117
118// access the database class
119$database->backup()->create();
120
121// rollback the backup (number for 1 = last)
122$database->backup()->restore($number);
123
124// delete backup (number of backup)
125$database->backup()->delete($number);