@onurege3467/zerohelper 2.1.2 → 3.1.0
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/database/index.js +14 -0
- package/database/mysql/structures/methods/add.js +16 -18
- package/database/mysql/structures/methods/all.js +22 -21
- package/database/mysql/structures/methods/auto_increment.js +13 -10
- package/database/mysql/structures/methods/base_get.js +11 -9
- package/database/mysql/structures/methods/base_set.js +18 -10
- package/database/mysql/structures/methods/clear.js +13 -12
- package/database/mysql/structures/methods/delete.js +28 -21
- package/database/mysql/structures/methods/exists.js +12 -10
- package/database/mysql/structures/methods/get.js +37 -37
- package/database/mysql/structures/methods/has.js +39 -37
- package/database/mysql/structures/methods/includes.js +14 -10
- package/database/mysql/structures/methods/pull.js +20 -16
- package/database/mysql/structures/methods/push.js +20 -17
- package/database/mysql/structures/methods/set.js +58 -46
- package/database/mysql/structures/methods/stats.js +10 -7
- package/database/mysql/structures/methods/sub.js +16 -18
- package/database/postgresql/index.js +118 -0
- package/database/redis/index.js +102 -0
- package/functions/index.js +287 -0
- package/index.js +2 -7
- package/package.json +15 -8
- package/readme.md +293 -63
- package/database/test.js +0 -50
- package/functions/functions.js +0 -100
package/database/index.js
CHANGED
|
@@ -6,6 +6,8 @@ var JsonDatabase = require("./jsondatabase/index");
|
|
|
6
6
|
var MongoDB = require("./mongodb/index");
|
|
7
7
|
var MySQLDatabase = require("./mysql/index");
|
|
8
8
|
var SQLiteDatabase = require("./sqldb/index");
|
|
9
|
+
var RedisDatabase = require("./redis/index");
|
|
10
|
+
var PostgreSQL = require("./postgresql/index");
|
|
9
11
|
|
|
10
12
|
module.exports = {
|
|
11
13
|
/**
|
|
@@ -31,4 +33,16 @@ module.exports = {
|
|
|
31
33
|
* @type {SQLiteDatabase}
|
|
32
34
|
*/
|
|
33
35
|
SQLiteDatabase,
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Redis-based database.
|
|
39
|
+
* @type {RedisDatabase}
|
|
40
|
+
*/
|
|
41
|
+
RedisDatabase,
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* PostgreSQL-based database.
|
|
45
|
+
* @type {PostgreSQL}
|
|
46
|
+
*/
|
|
47
|
+
PostgreSQL,
|
|
34
48
|
};
|
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const errors = require(
|
|
3
|
+
const errors = require("../errors/strings.js");
|
|
4
4
|
|
|
5
|
-
module.exports = async function(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return res;
|
|
21
|
-
}
|
|
5
|
+
module.exports = async function (key, value, table = "default") {
|
|
6
|
+
if (!table || typeof table !== "string")
|
|
7
|
+
throw new TypeError(errors.table.replace("{received}", typeof table));
|
|
8
|
+
if (!key || typeof key !== "string")
|
|
9
|
+
throw new TypeError(errors.key.replace("{received}", typeof key));
|
|
10
|
+
if (value === undefined)
|
|
11
|
+
throw new TypeError(errors.value.replace("{received}", typeof value));
|
|
12
|
+
if (isNaN(value) || value <= 0)
|
|
13
|
+
throw new TypeError(errors.numberType.replace("{received}", typeof value));
|
|
14
|
+
|
|
15
|
+
await this.create(table);
|
|
16
|
+
let data = (await this.get(table, key)) || 0;
|
|
17
|
+
if (isNaN(data)) throw new TypeError(errors.notNumber.replace("{key}", key));
|
|
18
|
+
return await this.set(key, Number(data) + Number(value), table);
|
|
19
|
+
};
|
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const errors = require(
|
|
3
|
+
const errors = require("../errors/strings.js");
|
|
4
4
|
|
|
5
|
-
module.exports = async function(table){
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
5
|
+
module.exports = async function (table = "default") {
|
|
6
|
+
if (!table || typeof table !== "string")
|
|
7
|
+
throw new TypeError(errors.table.replace("{received}", typeof table));
|
|
8
|
+
|
|
9
|
+
let all = await this.query(`SELECT * from \`${table}\``);
|
|
10
|
+
let res = [];
|
|
11
|
+
all.forEach((obj) => {
|
|
12
|
+
obj.ID = obj.key_name;
|
|
13
|
+
let data = obj.value;
|
|
14
|
+
if (!isNaN(data)) data = Number(data);
|
|
15
|
+
try {
|
|
16
|
+
data = JSON.parse(data);
|
|
17
|
+
} catch (e) {}
|
|
18
|
+
obj.data = data;
|
|
19
|
+
delete obj.id;
|
|
20
|
+
delete obj.key_name;
|
|
21
|
+
delete obj.value;
|
|
22
|
+
res.push(obj);
|
|
23
|
+
});
|
|
24
|
+
return res;
|
|
25
|
+
};
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const errors = require(
|
|
3
|
+
const errors = require("../errors/strings.js");
|
|
4
4
|
|
|
5
|
-
module.exports = async function(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
5
|
+
module.exports = async function (number, table = "default") {
|
|
6
|
+
if (!table || typeof table !== "string")
|
|
7
|
+
throw new TypeError(errors.table.replace("{received}", typeof table));
|
|
8
|
+
if (number == null || typeof number !== "number")
|
|
9
|
+
throw new TypeError(errors.number.replace("{received}", typeof number));
|
|
10
|
+
if (isNaN(number) || number < 1)
|
|
11
|
+
throw new TypeError(errors.numberType.replace("{received}", typeof number));
|
|
12
|
+
|
|
13
|
+
await this.query(`ALTER TABLE \`${table}\` AUTO_INCREMENT = ${number};`);
|
|
14
|
+
let res = await this.stats(table);
|
|
15
|
+
return res.Auto_increment;
|
|
16
|
+
};
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const errors = require(
|
|
3
|
+
const errors = require("../errors/strings.js");
|
|
4
4
|
|
|
5
|
-
module.exports = async function(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
module.exports = async function (key, table = "default") {
|
|
6
|
+
if (!table || typeof table !== "string")
|
|
7
|
+
throw new TypeError(errors.table.replace("{received}", typeof table));
|
|
8
|
+
if (!key || typeof key !== "string")
|
|
9
|
+
throw new TypeError(errors.key.replace("{received}", typeof key));
|
|
10
|
+
|
|
11
|
+
let data = await this.get(table, key);
|
|
12
|
+
if (typeof data !== "string") throw new TypeError(errors.baseNotString);
|
|
13
|
+
return Buffer.from(data, "base64").toString("binary");
|
|
14
|
+
};
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const errors = require(
|
|
3
|
+
const errors = require("../errors/strings.js");
|
|
4
4
|
|
|
5
|
-
module.exports = async function(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
module.exports = async function (key, value, table = "default") {
|
|
6
|
+
if (!table || typeof table !== "string")
|
|
7
|
+
throw new TypeError(errors.table.replace("{received}", typeof table));
|
|
8
|
+
if (!key || typeof key !== "string")
|
|
9
|
+
throw new TypeError(errors.key.replace("{received}", typeof key));
|
|
10
|
+
if (value === undefined)
|
|
11
|
+
throw new TypeError(errors.value.replace("{received}", typeof value));
|
|
12
|
+
if (typeof value !== "string") throw new TypeError(errors.baseNotString);
|
|
13
|
+
|
|
14
|
+
await this.set(
|
|
15
|
+
table,
|
|
16
|
+
key,
|
|
17
|
+
Buffer.from(value, "binary").toString("base64"),
|
|
18
|
+
true
|
|
19
|
+
);
|
|
20
|
+
return this.base_get(table, key);
|
|
21
|
+
};
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const errors = require(
|
|
3
|
+
const errors = require("../errors/strings.js");
|
|
4
4
|
|
|
5
|
-
module.exports = async function(table){
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
module.exports = async function (table = "default") {
|
|
6
|
+
if (!table || typeof table !== "string")
|
|
7
|
+
throw new TypeError(errors.table.replace("{received}", typeof table));
|
|
8
|
+
|
|
9
|
+
let tables = await this.tables();
|
|
10
|
+
if (!tables.includes(table)) return false;
|
|
11
|
+
let all = await this.all(table);
|
|
12
|
+
if (!all.length) return false;
|
|
13
|
+
await this.drop(table, true);
|
|
14
|
+
this.emit("tableClear", table);
|
|
15
|
+
return this.create(table, true);
|
|
16
|
+
};
|
|
@@ -1,24 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const unset = require(
|
|
4
|
-
const errors = require(
|
|
3
|
+
const unset = require("lodash/unset");
|
|
4
|
+
const errors = require("../errors/strings.js");
|
|
5
5
|
|
|
6
|
-
module.exports = async function(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
6
|
+
module.exports = async function (key, table = "default") {
|
|
7
|
+
if (!key || typeof key !== "string")
|
|
8
|
+
throw new TypeError(errors.key.replace("{received}", typeof key));
|
|
9
|
+
|
|
10
|
+
let res = true;
|
|
11
|
+
let keys = key.split(".");
|
|
12
|
+
if (keys.length > 1) {
|
|
13
|
+
key = keys.shift();
|
|
14
|
+
let data = (await this.get(table, key)) || {};
|
|
15
|
+
if (typeof data !== "object")
|
|
16
|
+
throw new TypeError(errors.targetNotObject.replace("{key}", key));
|
|
17
|
+
res = unset(data, keys.join("."));
|
|
18
|
+
await this.set(key, data, table);
|
|
19
|
+
} else {
|
|
20
|
+
let oldData = await this.get(table, key);
|
|
21
|
+
await this.query(`DELETE FROM \`${table}\` WHERE key_name = '${key}'`);
|
|
22
|
+
this.emit("dataModification", {
|
|
23
|
+
oldData,
|
|
24
|
+
newData: null,
|
|
25
|
+
type: "DELETE",
|
|
26
|
+
table,
|
|
27
|
+
modifiedAt: Date.now(),
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return res;
|
|
31
|
+
};
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const errors = require(
|
|
3
|
+
const errors = require("../errors/strings.js");
|
|
4
4
|
|
|
5
|
-
module.exports = async function(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
module.exports = async function (key, table = "default") {
|
|
6
|
+
if (!table || typeof table !== "string")
|
|
7
|
+
throw new TypeError(errors.table.replace("{received}", typeof table));
|
|
8
|
+
if (!key || typeof key !== "string")
|
|
9
|
+
throw new TypeError(errors.key.replace("{received}", typeof key));
|
|
10
|
+
|
|
11
|
+
let tables = await this.tables();
|
|
12
|
+
if (!tables.includes(table)) return false;
|
|
13
|
+
let data = await this.get(table, key);
|
|
14
|
+
return data != null ? true : false;
|
|
15
|
+
};
|
|
@@ -1,40 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const get = require(
|
|
4
|
-
const errors = require(
|
|
3
|
+
const get = require("lodash/get");
|
|
4
|
+
const errors = require("../errors/strings.js");
|
|
5
5
|
|
|
6
|
-
module.exports = async function(
|
|
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
|
-
}
|
|
6
|
+
module.exports = async function (key, table = "default") {
|
|
7
|
+
if (!key || typeof key !== "string")
|
|
8
|
+
throw new TypeError(errors.key.replace("{received}", typeof key));
|
|
9
|
+
|
|
10
|
+
let tables = await this.tables();
|
|
11
|
+
if (!tables.includes(table)) return null;
|
|
12
|
+
|
|
13
|
+
let keys = key.split("."),
|
|
14
|
+
keys2 = key.split(".");
|
|
15
|
+
if (keys.length > 1) {
|
|
16
|
+
key = keys.shift();
|
|
17
|
+
}
|
|
18
|
+
let res = await this.query({
|
|
19
|
+
sql: `SELECT value FROM \`${table}\` WHERE \`key_name\` = ?`,
|
|
20
|
+
values: [key],
|
|
21
|
+
});
|
|
22
|
+
if (!res.length) return null;
|
|
23
|
+
let value = null;
|
|
24
|
+
if (res.length) {
|
|
25
|
+
value = res[0].value;
|
|
26
|
+
if (!isNaN(value)) {
|
|
27
|
+
value = Number(value);
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
value = JSON.parse(value);
|
|
31
|
+
} catch (e) {}
|
|
32
|
+
}
|
|
33
|
+
if (keys2.length > 1 && typeof value === "object") {
|
|
34
|
+
value = get(value, keys.join("."));
|
|
35
|
+
if (value == undefined) value = null;
|
|
36
|
+
} else if (keys2.length > 1) {
|
|
37
|
+
throw new ReferenceError(errors.targetNotObject.replace("{key}", key));
|
|
38
|
+
}
|
|
39
|
+
return value;
|
|
40
|
+
};
|
|
@@ -1,40 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const get = require(
|
|
4
|
-
const errors = require(
|
|
3
|
+
const get = require("lodash/get");
|
|
4
|
+
const errors = require("../errors/strings.js");
|
|
5
5
|
|
|
6
|
-
module.exports = async function(
|
|
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
|
-
}
|
|
6
|
+
module.exports = async function (key, table = "default") {
|
|
7
|
+
if (!table || typeof table !== "string")
|
|
8
|
+
throw new TypeError(errors.table.replace("{received}", typeof table));
|
|
9
|
+
if (!key || typeof key !== "string")
|
|
10
|
+
throw new TypeError(errors.key.replace("{received}", typeof key));
|
|
11
|
+
|
|
12
|
+
let tables = await this.tables();
|
|
13
|
+
if (!tables.includes(table)) return null;
|
|
14
|
+
|
|
15
|
+
let keys = key.split("."),
|
|
16
|
+
keys2 = key.split(".");
|
|
17
|
+
if (keys.length > 1) {
|
|
18
|
+
key = keys.shift();
|
|
19
|
+
}
|
|
20
|
+
let res = await this.query({
|
|
21
|
+
sql: `SELECT value FROM \`${table}\` WHERE \`key_name\` = ?`,
|
|
22
|
+
values: [key],
|
|
23
|
+
});
|
|
24
|
+
if (!res.length) return null;
|
|
25
|
+
let value = null;
|
|
26
|
+
if (res.length) {
|
|
27
|
+
value = res[0].value;
|
|
28
|
+
if (!isNaN(value)) {
|
|
29
|
+
value = Number(value);
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
value = JSON.parse(value);
|
|
33
|
+
} catch (e) {}
|
|
34
|
+
}
|
|
35
|
+
if (keys2.length > 1 && typeof value === "object") {
|
|
36
|
+
value = get(value, keys.join("."));
|
|
37
|
+
if (value == undefined) value = null;
|
|
38
|
+
} else if (keys2.length > 1) {
|
|
39
|
+
throw new ReferenceError(errors.targetNotObject.replace("{key}", key));
|
|
40
|
+
}
|
|
41
|
+
return value ? false : true;
|
|
42
|
+
};
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const errors = require(
|
|
3
|
+
const errors = require("../errors/strings.js");
|
|
4
4
|
|
|
5
|
-
module.exports = async function(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
module.exports = async function (key, value, table = "default") {
|
|
6
|
+
if (!table || typeof table !== "string")
|
|
7
|
+
throw new TypeError(errors.table.replace("{received}", typeof table));
|
|
8
|
+
if (!key || typeof key !== "string")
|
|
9
|
+
throw new TypeError(errors.key.replace("{received}", typeof key));
|
|
10
|
+
if (value === undefined)
|
|
11
|
+
throw new TypeError(errors.value.replace("{received}", typeof value));
|
|
12
|
+
|
|
13
|
+
let data = (await this.get(table, key)) || [];
|
|
14
|
+
if (!Array.isArray(data))
|
|
15
|
+
throw new TypeError(errors.array.replace("{key}", key));
|
|
16
|
+
return data.includes(value);
|
|
17
|
+
};
|
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const errors = require(
|
|
3
|
+
const errors = require("../errors/strings.js");
|
|
4
4
|
|
|
5
|
-
module.exports = async function(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
5
|
+
module.exports = async function (key, value, table = "default", option) {
|
|
6
|
+
if (!table || typeof table !== "string")
|
|
7
|
+
throw new TypeError(errors.table.replace("{received}", typeof table));
|
|
8
|
+
if (!key || typeof key !== "string")
|
|
9
|
+
throw new TypeError(errors.key.replace("{received}", typeof key));
|
|
10
|
+
if (value === undefined)
|
|
11
|
+
throw new TypeError(errors.value.replace("{received}", typeof value));
|
|
12
|
+
|
|
13
|
+
let data = await this.get(table, key);
|
|
14
|
+
if (!data) throw new TypeError(errors.dataNotFound.replace("{key}", key));
|
|
15
|
+
if (!Array.isArray(data))
|
|
16
|
+
throw new TypeError(errors.array.replace("{key}", key));
|
|
17
|
+
if (option && (option === true || option.toLowerCase() === "all")) {
|
|
18
|
+
data = data.filter((obj) => obj !== value);
|
|
19
|
+
} else {
|
|
20
|
+
if (data.includes(value)) data.splice(data.indexOf(value), 1);
|
|
21
|
+
}
|
|
22
|
+
return await this.set(key, data, table);
|
|
23
|
+
};
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const errors = require(
|
|
3
|
+
const errors = require("../errors/strings.js");
|
|
4
4
|
|
|
5
|
-
module.exports = async function(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
5
|
+
module.exports = async function (key, value, table = "default", option) {
|
|
6
|
+
if (!table || typeof table !== "string")
|
|
7
|
+
throw new TypeError(errors.table.replace("{received}", typeof table));
|
|
8
|
+
if (!key || typeof key !== "string")
|
|
9
|
+
throw new TypeError(errors.key.replace("{received}", typeof key));
|
|
10
|
+
if (value === undefined)
|
|
11
|
+
throw new TypeError(errors.value.replace("{received}", typeof value));
|
|
12
|
+
|
|
13
|
+
await this.create(table);
|
|
14
|
+
let data = (await this.get(table, key)) || [];
|
|
15
|
+
if (!Array.isArray(data))
|
|
16
|
+
throw new TypeError(errors.array.replace("{key}", key));
|
|
17
|
+
if (option === true) {
|
|
18
|
+
if (!data.includes(value)) data.push(value);
|
|
19
|
+
} else {
|
|
20
|
+
data.push(value);
|
|
21
|
+
}
|
|
22
|
+
return await this.set(key, data, table);
|
|
23
|
+
};
|