-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdatabase.mongogx.js
77 lines (67 loc) · 1.55 KB
/
database.mongogx.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
if(typeof(OGX) === 'undefined'){
var OGX = {};
}
OGX.MongogxDatabase = class{
constructor(__name, __data, __collection_name){
this.name = __name;
this.collection = null;
this.collections = __data;
this._initCollections();
if(typeof(__collection_name) !== 'undefined'){
this.setCollection(__collection_name);
}
}
setCollection(__name){
if(this.collections.hasOwnProperty(__name)){
this.collection = __name;
return true;
}
return false;
}
getCollections(){
let cols = [];
for(let a in this.collections){
cols.push(a);
}
return cols;
}
getCollection(__name){
if(typeof(__name) === 'undefined' && this.collection){
__name = this.collection;
}
if(!this.collections.hasOwnProperty(__name)){
return false;
}
return this.collections[__name];
}
createCollection(__name){
if(this.collections.hasOwnProperty(__name)){
return false;
}
this.collections[__name] = new OGX.MongogxCollection(__name, {});
return this.collections[__name];
}
deleteCollection(__name){
if(!this.collections.hasOwnProperty(__name)){
return false;
}
delete this.collections[__name];
}
clearCollection(__name){
if(!this.collections.hasOwnProperty(__name)){
return false;
}
return this.collections[__name].remove();
}
hasCollection(__name){
return this.collections.hasOwnProperty(__name);
}
_initCollections(){
for(let a in this.collections){
this.collections[a] = new OGX.MongogxCollection(a, this.collections[a]);
}
}
toJSON(){
return this.collections;
}
};