-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_db.js
155 lines (140 loc) · 4.77 KB
/
test_db.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
const wett_firestore = require("../wett-firestore/index");
global.engine = require("./index");
require('dotenv').config();
main();
async function main(){
let log = true;
let install = await engine.db().install(wett_firestore);
if(install instanceof engine.common.Error){
return install.now("failed-install-wett-firebase-plugin").log(log);
}
let init = await engine.db("firestore").init({
name:'firestore',
cred:require(process.env.DB_FIREBASE_CRED),
url:require(process.env.DB_FIREBASE_URL).testDBURL
});
if(init instanceof engine.common.Error){
return init.now("init failed").log(log);
}
console.log({init:init});
if(false){
let add = await engine.db("firestore").collection("test").doc("test0")
.insert({
count:0,
some:true
})
.then(()=>{return true;})
.catch(()=>{return false;});
console.log({add:add});
}
if(false){
let get_doc = await engine.db("firestore").collection("test").doc("test0")
.get()
.then((d)=>{return d;})
.catch((e)=>{
console.log(e);
return false;
});
console.log({get_doc:get_doc});
}
if(false){
const test_anchor = await engine.db("firestore").collection("test").doc("test4")
.get(true)
.then((d)=>{return d;})
.catch((e)=>{
console.log(e);
return false;
});
if(!test_anchor){return new Error("failed-get-test_anchor_doc").log();}
// console.log({test_anchor:test_anchor});
let get_collection = await engine.db("firestore").collection("test")
.where("count",">",0)
.limit(4)
.orderBy("count",'asc')
.after(test_anchor)
.get(true)
.then((d)=>{return d;})
.catch((e)=>{
console.log(e);
return false;
});
console.log({get_collection:get_collection});
}
if(true){
let exists = await engine.db("firestore").collection("test").doc("test0")
.exists()
.then((d)=>{return d;})
.catch((e)=>{
console.log(e);
return false;
});
console.log({exists:exists});
}
if(false){
let update = await engine.db("firestore").collection("test").doc("test0")
.update({
update:true
})
.then(()=>{return true;})
.catch(()=>{return false;});
console.log({update:update});
}
if(false){
let increment = await engine.db("firestore").collection("test").doc("test0")
.increment({
count:1
})
.then(()=>{return true;})
.catch(()=>{return false;});
console.log({increment:increment});
}
if(false){
let del = await engine.db("firestore").collection("test").doc("test0")
.delete()
.then(()=>{return true;})
.catch(()=>{return false;});
console.log({delete:del});
}
if(false){
let batch = engine.db("firestore").batch();
if(true){
batch.collection("test").doc("test0").insert({count:0,some:true});
batch.collection("test").doc("test1").insert({count:1,some:true});
batch.collection("test").doc("test2").insert({count:2,some:true});
batch.collection("test").doc("test3").insert({count:3,some:true});
batch.collection("test").doc("test4").insert({count:4,some:true});
batch.collection("test").doc("test5").insert({count:5,some:true});
batch.collection("test").doc("test6").insert({count:6,some:true});
batch.collection("test").doc("test7").insert({count:7,some:true});
batch.collection("test").doc("test8").insert({count:8,some:true});
batch.collection("test").doc("test9").insert({count:9,some:true});
}
if(false){
batch.collection("test").doc("test0").increment({count:1});
batch.collection("test").doc("test1").increment({count:1});
batch.collection("test").doc("test2").increment({count:1});
}
if(false){
batch.collection("test").doc("test0").update({some:true});
batch.collection("test").doc("test1").update({some:true});
batch.collection("test").doc("test2").update({some:true});
}
if(false){
batch.collection("test").doc("test2").delete();
}
if(false){
console.log(batch.flush());
}
if(true){
let commit = await batch.commit()
.then(()=>{
return true;
})
.catch((e)=>{
console.log(e);
return false;
});
console.log({commit:commit});
}
}
}