@onurege3467/zerohelper 5.0.3 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/data/test_db.json +3 -0
- package/data/test_db.sqlite +0 -0
- package/data/test_db_cached.sqlite +0 -0
- package/database/cacheWrapper.js +121 -0
- package/database/index.js +24 -6
- package/database/{adapters/json.js → json.js} +9 -9
- package/database/{adapters/mongodb.js → mongodb.js} +1 -0
- package/database/{adapters/mysql.js → mysql.js} +12 -12
- package/database/{adapters/sqlite.js → sqlite.js} +86 -77
- package/functions/index.js +14 -4
- package/package.json +4 -3
- package/readme.md +111 -324
- package/test.js +244 -0
- package/database/csvdb/index.js +0 -90
- package/database/jsondatabase/index.js +0 -132
- package/database/migrate/index.js +0 -68
- package/database/mongodb/index.js +0 -49
- package/database/mongodb/src/client/Client.js +0 -37
- package/database/mongodb/src/structers/Collection.js +0 -136
- package/database/mongodb/src/structers/Data.js +0 -282
- package/database/mongodb/src/structers/Database.js +0 -53
- package/database/mongodb/src/tools/FormatTool.js +0 -5
- package/database/mysql/examples/example.js +0 -301
- package/database/mysql/index.js +0 -1
- package/database/mysql/structures/classes/MySQL.js +0 -41
- package/database/mysql/structures/errors/strings.js +0 -23
- package/database/mysql/structures/methods/add.js +0 -19
- package/database/mysql/structures/methods/all.js +0 -25
- package/database/mysql/structures/methods/auto_increment.js +0 -16
- package/database/mysql/structures/methods/base_get.js +0 -14
- package/database/mysql/structures/methods/base_set.js +0 -21
- package/database/mysql/structures/methods/clear.js +0 -16
- package/database/mysql/structures/methods/connect.js +0 -15
- package/database/mysql/structures/methods/create.js +0 -11
- package/database/mysql/structures/methods/create_db.js +0 -10
- package/database/mysql/structures/methods/delete.js +0 -31
- package/database/mysql/structures/methods/drop.js +0 -13
- package/database/mysql/structures/methods/end.js +0 -7
- package/database/mysql/structures/methods/exists.js +0 -15
- package/database/mysql/structures/methods/get.js +0 -40
- package/database/mysql/structures/methods/getAllData.js +0 -35
- package/database/mysql/structures/methods/has.js +0 -42
- package/database/mysql/structures/methods/includes.js +0 -17
- package/database/mysql/structures/methods/ping.js +0 -11
- package/database/mysql/structures/methods/process.js +0 -7
- package/database/mysql/structures/methods/pull.js +0 -23
- package/database/mysql/structures/methods/push.js +0 -23
- package/database/mysql/structures/methods/query.js +0 -9
- package/database/mysql/structures/methods/rename.js +0 -16
- package/database/mysql/structures/methods/set.js +0 -60
- package/database/mysql/structures/methods/stats.js +0 -13
- package/database/mysql/structures/methods/sub.js +0 -19
- package/database/mysql/structures/methods/tables.js +0 -8
- package/database/mysql/structures/methods/variables.js +0 -20
- package/database/newMongoDB/index.js +0 -94
- package/database/newMySQL/index.js +0 -205
- package/database/newSQLite/index.js +0 -240
- package/database/postgresql/index.js +0 -150
- package/database/redis/index.js +0 -125
- package/database/sqldb/index.js +0 -243
- package/database/yamldatabase/index.js +0 -76
- /package/database/{adapters/IDatabase.js → IDatabase.js} +0 -0
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
const mongodb = require("mongodb");
|
|
2
|
-
const { Data } = require("./Data.js");
|
|
3
|
-
|
|
4
|
-
const PathFormat = require("../tools/FormatTool.js");
|
|
5
|
-
|
|
6
|
-
class Collection {
|
|
7
|
-
/**
|
|
8
|
-
* @type {mongodb.Collection}
|
|
9
|
-
*/
|
|
10
|
-
Collection;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @param {mongodb.Collection} client
|
|
14
|
-
*/
|
|
15
|
-
constructor(collection) {
|
|
16
|
-
this.Collection = collection;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* If data does not exists, creates data then returns the data. Otherwise just returns data.
|
|
21
|
-
* @param {String} key
|
|
22
|
-
* @return {Data}
|
|
23
|
-
*/
|
|
24
|
-
data(key) {
|
|
25
|
-
return new Data(key, this.Collection);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Drop the data in collection.
|
|
30
|
-
* @param {String} key
|
|
31
|
-
* @return {Data}
|
|
32
|
-
*/
|
|
33
|
-
async dropData(key) {
|
|
34
|
-
return this.Collection.deleteOne({ key: key });
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Sorts all data by the value in the specified path.
|
|
39
|
-
* @param {String} path It determines the field where the sorting will be done.
|
|
40
|
-
* @param {("DESC"|"ASC")} orderType Sorts the data in DESC (descending) or ASC (ascending).
|
|
41
|
-
* @param {number} limit It determines the data limit to be received.
|
|
42
|
-
* @return {Array<any>}
|
|
43
|
-
*/
|
|
44
|
-
async sort(path, orderType, limit = 0) {
|
|
45
|
-
path = PathFormat(path);
|
|
46
|
-
|
|
47
|
-
const order = orderType == "DESC" ? -1 : 1;
|
|
48
|
-
const data = await this.Collection.find({ [path]: { $exists: true } }).sort(path, order).limit(limit).toArray();
|
|
49
|
-
|
|
50
|
-
return data;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* In all data, the value is assigned to the specified path.
|
|
55
|
-
* @param {String} path
|
|
56
|
-
* @param {any} value
|
|
57
|
-
* @return {mongodb.UpdateWriteOpResult}
|
|
58
|
-
*/
|
|
59
|
-
async set(path, value) {
|
|
60
|
-
path = PathFormat(path);
|
|
61
|
-
|
|
62
|
-
return await this.Collection.updateMany({}, { $set: { [path]: value } }, { upsert: true });
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Removes a field from all data in the collection.
|
|
67
|
-
* @param {String} path
|
|
68
|
-
* @return {mongodb.UpdateWriteOpResult}
|
|
69
|
-
*/
|
|
70
|
-
async delete(path) {
|
|
71
|
-
path = PathFormat(path);
|
|
72
|
-
|
|
73
|
-
return await this.Collection.updateMany({}, { $unset: { [path]: "" } }, { upsert: true });
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Perform mathematical addition in the specified path in all data.
|
|
78
|
-
* @param {String} path
|
|
79
|
-
* @param {Number} value
|
|
80
|
-
* @return {mongodb.UpdateWriteOpResult}
|
|
81
|
-
*/
|
|
82
|
-
async add(path, value) {
|
|
83
|
-
path = PathFormat(path);
|
|
84
|
-
|
|
85
|
-
return await this.Collection.updateMany({}, { $inc: { [path]: Math.abs(value) } }, { upsert: true });
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Perform mathematical subtraction in the specified path in all data.
|
|
89
|
-
* @param {String} path
|
|
90
|
-
* @param {Number} value
|
|
91
|
-
* @return {mongodb.UpdateWriteOpResult}
|
|
92
|
-
*/
|
|
93
|
-
async sub(path, value) {
|
|
94
|
-
path = PathFormat(path);
|
|
95
|
-
|
|
96
|
-
return await this.Collection.updateMany({}, { $inc: { [path]: -Math.abs(value) } }, { upsert: true });
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Push value to array in specified path in all data.
|
|
101
|
-
* @param {String} path
|
|
102
|
-
* @param {any} value
|
|
103
|
-
* @return {mongodb.UpdateWriteOpResult}
|
|
104
|
-
*/
|
|
105
|
-
async push(path, value) {
|
|
106
|
-
path = PathFormat(path);
|
|
107
|
-
|
|
108
|
-
return await this.Collection.updateMany({}, { $push: { [path]: value } }, { upsert: true });
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Values in the specified array are added to all data in the collection in the specified path.
|
|
113
|
-
* @param {String} path
|
|
114
|
-
* @param {any[]} values
|
|
115
|
-
* @return {mongodb.UpdateWriteOpResult}
|
|
116
|
-
*/
|
|
117
|
-
async pushRange(path, values) {
|
|
118
|
-
path = PathFormat(path);
|
|
119
|
-
|
|
120
|
-
return await this.Collection.updateMany({}, { $push: { [path]: { $each: values } } }, { upsert: true });
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Pull the value from the array in the specified path in all data.
|
|
125
|
-
* @param {String} path
|
|
126
|
-
* @param {any} value
|
|
127
|
-
* @return {mongodb.UpdateWriteOpResult}
|
|
128
|
-
*/
|
|
129
|
-
async pull(path, value) {
|
|
130
|
-
path = PathFormat(path);
|
|
131
|
-
|
|
132
|
-
return await this.Collection.updateMany({}, { $pull: { [path]: value } }, { upsert: true });
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
module.exports = { Collection };
|
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
const mongodb = require("mongodb");
|
|
2
|
-
const PathFormat = require("../tools/FormatTool.js");
|
|
3
|
-
|
|
4
|
-
class Data {
|
|
5
|
-
/**
|
|
6
|
-
* @type {mongodb.Collection}
|
|
7
|
-
*/
|
|
8
|
-
#collection;
|
|
9
|
-
/**
|
|
10
|
-
* @type {String}
|
|
11
|
-
*/
|
|
12
|
-
#key;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
*
|
|
16
|
-
* @param {String} key
|
|
17
|
-
* @param {mongodb.Collection} collection
|
|
18
|
-
*/
|
|
19
|
-
constructor(key, collection) {
|
|
20
|
-
this.#key = key;
|
|
21
|
-
this.#collection = collection;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Assign to the specified path.
|
|
26
|
-
* @param {String} path
|
|
27
|
-
* @param {any} value Value to be assigned.
|
|
28
|
-
* @return {any}
|
|
29
|
-
*/
|
|
30
|
-
async set(path, value) {
|
|
31
|
-
path = PathFormat(path);
|
|
32
|
-
|
|
33
|
-
await this.#collection.updateOne(
|
|
34
|
-
{ key: this.#key },
|
|
35
|
-
{ $set: { [path]: value } },
|
|
36
|
-
{ upsert: true }
|
|
37
|
-
);
|
|
38
|
-
return value;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Deletes the specified path.
|
|
43
|
-
* @param {String} path
|
|
44
|
-
* @return {Promise<void>}
|
|
45
|
-
*/
|
|
46
|
-
async delete(path) {
|
|
47
|
-
path = PathFormat(path);
|
|
48
|
-
|
|
49
|
-
await this.#collection.updateOne(
|
|
50
|
-
{ key: this.#key },
|
|
51
|
-
{ $unset: { [path]: "" } }
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Returns the value/object at the specified path.
|
|
57
|
-
* @param {String} path
|
|
58
|
-
* @return {any}
|
|
59
|
-
*/
|
|
60
|
-
async get(path) {
|
|
61
|
-
path = PathFormat(path);
|
|
62
|
-
|
|
63
|
-
const data = await this.#collection.findOne(
|
|
64
|
-
{ key: this.#key },
|
|
65
|
-
{
|
|
66
|
-
projection: {
|
|
67
|
-
result: `$${path}`,
|
|
68
|
-
},
|
|
69
|
-
}
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
return data ? data.result : undefined;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
async getAll() {
|
|
76
|
-
const data = await this.#collection.findOne({ key: this.#key });
|
|
77
|
-
|
|
78
|
-
return data ? data.data : {};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
async getAllData() {
|
|
82
|
-
this.getAll().then((data) => {
|
|
83
|
-
if (!data) data = {};
|
|
84
|
-
return data;
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
async ping() {
|
|
89
|
-
var run1 = Date.now();
|
|
90
|
-
await this.set(`${run1}`, 1);
|
|
91
|
-
var set = Date.now();
|
|
92
|
-
var run2 = Date.now();
|
|
93
|
-
await this.get(run1);
|
|
94
|
-
var get = Date.now();
|
|
95
|
-
var run3 = Date.now();
|
|
96
|
-
await this.delete(run1);
|
|
97
|
-
var deletet = Date.now();
|
|
98
|
-
|
|
99
|
-
return {
|
|
100
|
-
total: (get + set + deletet) / 3 - run1,
|
|
101
|
-
set: set - run1,
|
|
102
|
-
get: get - run2,
|
|
103
|
-
delete: deletet - run3,
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Sorts the array/values in path.
|
|
109
|
-
* @param {String} path
|
|
110
|
-
* @param {("DESC"|"ASC")} orderType Sorts the data in DESC (descending) or ASC (ascending).
|
|
111
|
-
* @param {Number} limit determines how many elements will rotate. (Default: 0 this is mean of returns in array all elements)
|
|
112
|
-
* @return {Promise<any[]>}
|
|
113
|
-
*/
|
|
114
|
-
async sort(path, orderType, limit = 0) {
|
|
115
|
-
path = PathFormat(path);
|
|
116
|
-
|
|
117
|
-
const order = orderType == "DESC" ? -1 : 1;
|
|
118
|
-
const pipelines = [
|
|
119
|
-
{
|
|
120
|
-
$match: {
|
|
121
|
-
key: this.#key,
|
|
122
|
-
},
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
$unwind: {
|
|
126
|
-
path: `$${path}`,
|
|
127
|
-
},
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
$sort: {
|
|
131
|
-
[`${path}`]: order,
|
|
132
|
-
},
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
$project: {
|
|
136
|
-
element: `$${path}`,
|
|
137
|
-
},
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
$limit: limit,
|
|
141
|
-
},
|
|
142
|
-
];
|
|
143
|
-
|
|
144
|
-
let result = (await this.#collection.aggregate(pipelines).toArray()).map(
|
|
145
|
-
(e) => e.element
|
|
146
|
-
);
|
|
147
|
-
return result;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Do mathematical addition to specified path.
|
|
152
|
-
* @param {String} path
|
|
153
|
-
* @param {Number} value
|
|
154
|
-
* @return {any}
|
|
155
|
-
*/
|
|
156
|
-
async add(path, value) {
|
|
157
|
-
path = PathFormat(path);
|
|
158
|
-
|
|
159
|
-
const data = await this.#collection.findOneAndUpdate(
|
|
160
|
-
{ key: this.#key },
|
|
161
|
-
{ $inc: { [path]: value } },
|
|
162
|
-
{
|
|
163
|
-
projection: {
|
|
164
|
-
result: `$${path}`,
|
|
165
|
-
},
|
|
166
|
-
upsert: true,
|
|
167
|
-
new: true,
|
|
168
|
-
}
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
return data ? data.result : undefined;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Do mathematical subtraction to specified path.
|
|
176
|
-
* @param {String} path
|
|
177
|
-
* @param {Number} value
|
|
178
|
-
* @return {any}
|
|
179
|
-
*/
|
|
180
|
-
async sub(path, value) {
|
|
181
|
-
path = PathFormat(path);
|
|
182
|
-
|
|
183
|
-
const data = await this.#collection.findOneAndUpdate(
|
|
184
|
-
{ key: this.#key },
|
|
185
|
-
{ $inc: { [path]: -Math.abs(value) } },
|
|
186
|
-
{
|
|
187
|
-
projection: {
|
|
188
|
-
result: `$${path}`,
|
|
189
|
-
},
|
|
190
|
-
upsert: true,
|
|
191
|
-
new: true,
|
|
192
|
-
}
|
|
193
|
-
);
|
|
194
|
-
|
|
195
|
-
return data ? data.result : undefined;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Check if Field exists to specified path.
|
|
200
|
-
* @param {String} path
|
|
201
|
-
* @return {Promise<Boolean>}
|
|
202
|
-
*/
|
|
203
|
-
async has(path) {
|
|
204
|
-
path = PathFormat(path);
|
|
205
|
-
|
|
206
|
-
const data = await this.#collection.findOne(
|
|
207
|
-
{ key: this.#key, [path]: { $exists: true } },
|
|
208
|
-
{
|
|
209
|
-
projection: {
|
|
210
|
-
_id: 1,
|
|
211
|
-
},
|
|
212
|
-
}
|
|
213
|
-
);
|
|
214
|
-
return data ? true : false;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Push to value an array to specified path.
|
|
219
|
-
* @param {String} path
|
|
220
|
-
* @param {any} value
|
|
221
|
-
* @return {Promise<void>}
|
|
222
|
-
*/
|
|
223
|
-
async push(path, value) {
|
|
224
|
-
path = PathFormat(path);
|
|
225
|
-
|
|
226
|
-
await this.#collection.updateOne(
|
|
227
|
-
{ key: this.#key },
|
|
228
|
-
{ $push: { [path]: value } },
|
|
229
|
-
{ upsert: true }
|
|
230
|
-
);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Push to multiple values an array to specified path.
|
|
235
|
-
* @param {String} path
|
|
236
|
-
* @param {any[]} values
|
|
237
|
-
* @return {Promise<void>}
|
|
238
|
-
*/
|
|
239
|
-
async pushRange(path, values) {
|
|
240
|
-
path = PathFormat(path);
|
|
241
|
-
|
|
242
|
-
await this.#collection.updateOne(
|
|
243
|
-
{ key: this.#key },
|
|
244
|
-
{ $push: { [path]: { $each: values } } },
|
|
245
|
-
{ upsert: true }
|
|
246
|
-
);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Extract element from Array to specified path.
|
|
251
|
-
* @param {String} path
|
|
252
|
-
* @param {any} value
|
|
253
|
-
* @return {Promise<void>}
|
|
254
|
-
*/
|
|
255
|
-
async pull(path, value) {
|
|
256
|
-
path = PathFormat(path);
|
|
257
|
-
|
|
258
|
-
await this.#collection.updateOne(
|
|
259
|
-
{ key: this.#key },
|
|
260
|
-
{ $pull: { [path]: value } },
|
|
261
|
-
{ upsert: true }
|
|
262
|
-
);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* Extract all elements from Array to specified path.
|
|
267
|
-
* @param {String} path
|
|
268
|
-
* @param {any} value
|
|
269
|
-
* @return {Promise<void>}
|
|
270
|
-
*/
|
|
271
|
-
async pullAll(path, value) {
|
|
272
|
-
path = PathFormat(path);
|
|
273
|
-
|
|
274
|
-
await this.#collection.updateOne(
|
|
275
|
-
{ key: this.#key },
|
|
276
|
-
{ $pullAll: { [path]: value } },
|
|
277
|
-
{ upsert: true }
|
|
278
|
-
);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
module.exports = { Data };
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
const mongodb = require("mongodb");
|
|
2
|
-
const { Collection } = require("./Collection.js");
|
|
3
|
-
|
|
4
|
-
class Database {
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* It has Db feature in MongoDB. Most operations are done with this area.
|
|
8
|
-
* @type {mongodb.Db}
|
|
9
|
-
*/
|
|
10
|
-
Db;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* It carries the Client connected to MongoDB.
|
|
14
|
-
* @type {mongodb.MongoClient}
|
|
15
|
-
*/
|
|
16
|
-
Client;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
20
|
-
* @param {mongodb.MongoClient} client
|
|
21
|
-
* @param {mongodb.Db} databaseName
|
|
22
|
-
*/
|
|
23
|
-
constructor(client, databaseName) {
|
|
24
|
-
this.Client = client;
|
|
25
|
-
this.Db = this.Client.db(databaseName);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* If collection does not exists, creates collection then returns the collection. Otherwise just returns collection.
|
|
30
|
-
* @param {String} collectionName
|
|
31
|
-
* @return {Collection}
|
|
32
|
-
*/
|
|
33
|
-
collection(collectionName) {
|
|
34
|
-
const dbCollection = this.Db.collection(collectionName);
|
|
35
|
-
dbCollection.createIndex({ key: 1 });
|
|
36
|
-
const collection = new Collection(dbCollection);
|
|
37
|
-
|
|
38
|
-
return collection;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Drops the Database Collection.
|
|
43
|
-
* @param {String} collectionName
|
|
44
|
-
* @return {Promise<void>}
|
|
45
|
-
*/
|
|
46
|
-
async dropCollection(collectionName) {
|
|
47
|
-
const flag = await this.Db.dropCollection(collectionName);
|
|
48
|
-
|
|
49
|
-
return flag;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
module.exports = { Database };
|