ming_node 2.2.3 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +10 -0
- package/beforeTest/ApiCloudBaseRpcApiTest.js +17 -0
- package/beforeTest/FileBaseRpcApiTest.js +8 -0
- package/beforeTest/MemorDbTest.js +16 -0
- package/beforeTest/MemoryBaseRestApiTest.js +8 -0
- package/beforeTest/MemoryBaseRpcApiTest.js +8 -0
- package/beforeTest/MiApiCloudClientTest.js +16 -0
- package/beforeTest/MongoDbBaseRestApiTest.js +22 -0
- package/beforeTest/MongoDbBaseRpcApiTest.js +19 -0
- package/beforeTest/MySqlBaseRestApiTest.js +13 -0
- package/beforeTest/MysqlBaseRpcApiTest.js +18 -0
- package/beforeTest/graphql_test.js +12 -0
- package/beforeTest/installPluginTest.js +10 -0
- package/index.js +125 -28
- package/ming_node.md +4 -4
- package/module/BaseMapper.js +37 -4
- package/module/MemoryDb.js +136 -0
- package/module/MiApiCloudClient.js +649 -0
- package/package.json +1 -1
- package/plugins/BaseGraphqlApi/getGraphqlSchema.js +145 -0
- package/plugins/BaseGraphqlApi/getGraphqlSchemaDemo.js +76 -0
- package/plugins/BaseGraphqlApi/index.js +23 -0
- package/plugins/BaseRestApi/AbstractBaseRestApi.js +59 -0
- package/plugins/BaseRestApi/ApiCloudBaseRestApi.js +56 -0
- package/plugins/BaseRestApi/FileBaseRestApi.js +62 -0
- package/plugins/BaseRestApi/MemoryBaseRestApi.js +50 -0
- package/plugins/BaseRestApi/MongoDbBaseRestApi.js +75 -0
- package/plugins/BaseRestApi/MysqlBaseRestApi.js +72 -0
- package/plugins/BaseRpcApi/AbstractBaseRpcApi.js +72 -0
- package/plugins/BaseRpcApi/ApiCloudBaseRpcApi.js +57 -0
- package/plugins/BaseRpcApi/FileBaseRpcApi.js +62 -0
- package/plugins/BaseRpcApi/MemoryBaseRpcApi.js +50 -0
- package/plugins/BaseRpcApi/MongoDbBaseRpcApi.js +75 -0
- package/plugins/BaseRpcApi/MysqlBaseRpcApi.js +72 -0
- package/utils/common/CollectionUtils.js +28 -0
- package/beforeTest/t1.js +0 -18
@@ -0,0 +1,136 @@
|
|
1
|
+
/**
|
2
|
+
* File : MemoryDb.js
|
3
|
+
* By : Minglie
|
4
|
+
* QQ: 934031452
|
5
|
+
* Date :2021.09.14
|
6
|
+
* rem : 内存数据库
|
7
|
+
*/
|
8
|
+
|
9
|
+
const M=require("../index");
|
10
|
+
|
11
|
+
class MemoryDb{
|
12
|
+
|
13
|
+
constructor(tableName) {
|
14
|
+
this.tableName=tableName;
|
15
|
+
this.dataList=[]
|
16
|
+
}
|
17
|
+
|
18
|
+
/**
|
19
|
+
* 单个加
|
20
|
+
* @param obj
|
21
|
+
* @returns {Promise<*>}
|
22
|
+
*/
|
23
|
+
async add(obj){
|
24
|
+
obj.id = M.randomStr();
|
25
|
+
this.dataList=[...this.dataList,obj];
|
26
|
+
return obj;
|
27
|
+
}
|
28
|
+
|
29
|
+
async update(obj){
|
30
|
+
for (let i = 0; i < this.dataList.length; i++) {
|
31
|
+
if (this.dataList[i].id == obj.id) {
|
32
|
+
this.dataList[i]=obj;
|
33
|
+
return
|
34
|
+
}
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
listAll(caseObj){
|
39
|
+
let o_keys = Object.keys(caseObj);
|
40
|
+
if (caseObj && o_keys.length>0) {
|
41
|
+
let r_list = [];
|
42
|
+
let o_vals = Object.values(caseObj);
|
43
|
+
var d = this.dataList;
|
44
|
+
for (let i = 0; i < d.length; i++) {
|
45
|
+
let s=0;
|
46
|
+
for (let j=0;j<o_keys.length;j++){
|
47
|
+
if (d[i][o_keys[j]] != o_vals[j]) {
|
48
|
+
break
|
49
|
+
}
|
50
|
+
s++;
|
51
|
+
}
|
52
|
+
if(s==o_keys.length){
|
53
|
+
r_list.push(d[i]);
|
54
|
+
}
|
55
|
+
}
|
56
|
+
return r_list;
|
57
|
+
} else {
|
58
|
+
return this.dataList;
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
|
63
|
+
listByPage(startPage=0, limit=10, caseObj) {
|
64
|
+
startPage=Number.parseInt(startPage);
|
65
|
+
limit=Number.parseInt(limit);
|
66
|
+
if (startPage <= 0) startPage = 1;
|
67
|
+
let rows;
|
68
|
+
if (caseObj) {
|
69
|
+
rows = this.listAll(caseObj);
|
70
|
+
} else {
|
71
|
+
rows = this.listAll();
|
72
|
+
}
|
73
|
+
let total = rows.length;
|
74
|
+
rows=JSON.parse(JSON.stringify(rows))
|
75
|
+
rows = rows.splice((startPage - 1) * limit, limit)
|
76
|
+
return {rows, total}
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
deleteAll(o) {
|
81
|
+
if (o) {
|
82
|
+
let r_list = [];
|
83
|
+
let o_keys = Object.keys(o);
|
84
|
+
let o_vals = Object.values(o)
|
85
|
+
var d = this.dataList;
|
86
|
+
let delete_index=[]
|
87
|
+
for (let i = 0; i < d.length; i++) {
|
88
|
+
let s=0;
|
89
|
+
for (let j=0;j<o_keys.length;j++){
|
90
|
+
if (d[i][o_keys[j]] != o_vals[j]) {
|
91
|
+
break
|
92
|
+
}
|
93
|
+
s++;
|
94
|
+
}
|
95
|
+
if(s==o_keys.length){
|
96
|
+
delete_index.push(i)
|
97
|
+
}
|
98
|
+
}
|
99
|
+
for (let i = 0; i < d.length; i++) {
|
100
|
+
if(!delete_index.includes(i)){
|
101
|
+
r_list.push(d[i])
|
102
|
+
}
|
103
|
+
}
|
104
|
+
this.dataList=r_list;
|
105
|
+
return delete_index.length;
|
106
|
+
} else {
|
107
|
+
let length=this.dataList.length;
|
108
|
+
this.dataList=[];
|
109
|
+
return length;
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
getById(id) {
|
114
|
+
var d = this.dataList;
|
115
|
+
for (let i = 0; i < d.length; i++) {
|
116
|
+
if(d[i].id==id){
|
117
|
+
return d[i];
|
118
|
+
}
|
119
|
+
}
|
120
|
+
return null;
|
121
|
+
}
|
122
|
+
|
123
|
+
deleteById(id) {
|
124
|
+
var d = this.dataList;
|
125
|
+
for (let i = 0; i < d.length; i++) {
|
126
|
+
if(d[i].id==id){
|
127
|
+
this.dataList.splice(i, 1);
|
128
|
+
return id;
|
129
|
+
}
|
130
|
+
}
|
131
|
+
return 0;
|
132
|
+
}
|
133
|
+
}
|
134
|
+
|
135
|
+
|
136
|
+
module.exports = MemoryDb;
|