· 7 years ago · Mar 06, 2019, 03:40 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// change configs in run time
15$database->path='new path';
16
17// get a single Table (return a Table Class) if not exist will create
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')->find(0);
45// return bool if not found
46$document = $database->table('table_name')->findOrFail(0);
47
48// will return all
49$document = $database->table('table_name')->get();
50
51// edit and save the document
52// if the document does not exist, create
53$document = $database->table('table_name')->find(0);
54$document->name = 'Tim';
55$document->save();
56
57// update just new values ($data array)
58$document->update(array $data);
59
60// delete the document
61$document->delete();
62
63// create/insert new document ($data array)
64$database->table('table_name')->create($data);
65
66
67
68// DATABASE TABLE QUERY DOCUMENTS
69// -----------------------------------
70
71// multiple where statements (array) status = enabled and tag = php (returning a Collection of DOCUMENTS)
72// multi arrays inside single array
73$documents = $database->table('table_name')->where([
74 ['status','==','enabled'],
75 ['name','==','test'],
76])->get();
77// also many multi array without single array
78$documents = $database->table('table_name')->where(
79 ['status','==','enabled'],
80 ['name','==','test']
81)->get();
82
83also this methods working in orwhere
84
85// getting the first item of a query (Collection -> first())
86// $document = $database->table('table_name')->where(['name'=>'Tim'])->first();
87
88// using the quick where method (save as the above)
89// $document = $database->table('table_name')->whereName('Tim')->first();
90
91// using where operators
92$documents = $database->table('table_name')->where('email','LIKE','gmail')->get();
93
94// using order by and limit within query
95// $database->table('table_name')
96// ->where('email','LIKE','gmail')
97// ->orderBy('name','ASC')
98// ->limit(5)
99// ->get();
100
101
102 // ability to use where (closure) to run more advanced query statements
103 // WHERE status = 'enabled' AND (email LIKE '%gmail.com%' OR email LIKE '%yahoo.com%' OR )
104// $database->table('table_name')
105// ->whereStatus('enabled')
106// ->where(function($query){
107// $query->where('email','LIKE','gmail.com');
108// $query->orWhere('email','LIKE','yahoo.com');
109// })
110// ->get();
111
112
113// ability to delete all documents listed in results
114// $database->table('table_name')->where('email','LIKE','gmail')->delete();
115
116
117
118
119// DATABASE BACKUPS
120//
121// LETS THIS FEATURE LATER
122// -----------------------------------
123
124// access the database class
125// $database->backup();
126
127// // get a Collection of backups
128// $database->backup()->get();
129
130// // access the database class
131// $database->backup()->create();
132
133// // rollback the backup (number for 1 = last)
134// $database->backup()->restore($number);
135
136// // delete backup (number of backup)
137// $database->backup()->delete($number);