@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.
Files changed (62) hide show
  1. package/data/test_db.json +3 -0
  2. package/data/test_db.sqlite +0 -0
  3. package/data/test_db_cached.sqlite +0 -0
  4. package/database/cacheWrapper.js +121 -0
  5. package/database/index.js +24 -6
  6. package/database/{adapters/json.js → json.js} +9 -9
  7. package/database/{adapters/mongodb.js → mongodb.js} +1 -0
  8. package/database/{adapters/mysql.js → mysql.js} +12 -12
  9. package/database/{adapters/sqlite.js → sqlite.js} +86 -77
  10. package/functions/index.js +14 -4
  11. package/package.json +4 -3
  12. package/readme.md +111 -324
  13. package/test.js +244 -0
  14. package/database/csvdb/index.js +0 -90
  15. package/database/jsondatabase/index.js +0 -132
  16. package/database/migrate/index.js +0 -68
  17. package/database/mongodb/index.js +0 -49
  18. package/database/mongodb/src/client/Client.js +0 -37
  19. package/database/mongodb/src/structers/Collection.js +0 -136
  20. package/database/mongodb/src/structers/Data.js +0 -282
  21. package/database/mongodb/src/structers/Database.js +0 -53
  22. package/database/mongodb/src/tools/FormatTool.js +0 -5
  23. package/database/mysql/examples/example.js +0 -301
  24. package/database/mysql/index.js +0 -1
  25. package/database/mysql/structures/classes/MySQL.js +0 -41
  26. package/database/mysql/structures/errors/strings.js +0 -23
  27. package/database/mysql/structures/methods/add.js +0 -19
  28. package/database/mysql/structures/methods/all.js +0 -25
  29. package/database/mysql/structures/methods/auto_increment.js +0 -16
  30. package/database/mysql/structures/methods/base_get.js +0 -14
  31. package/database/mysql/structures/methods/base_set.js +0 -21
  32. package/database/mysql/structures/methods/clear.js +0 -16
  33. package/database/mysql/structures/methods/connect.js +0 -15
  34. package/database/mysql/structures/methods/create.js +0 -11
  35. package/database/mysql/structures/methods/create_db.js +0 -10
  36. package/database/mysql/structures/methods/delete.js +0 -31
  37. package/database/mysql/structures/methods/drop.js +0 -13
  38. package/database/mysql/structures/methods/end.js +0 -7
  39. package/database/mysql/structures/methods/exists.js +0 -15
  40. package/database/mysql/structures/methods/get.js +0 -40
  41. package/database/mysql/structures/methods/getAllData.js +0 -35
  42. package/database/mysql/structures/methods/has.js +0 -42
  43. package/database/mysql/structures/methods/includes.js +0 -17
  44. package/database/mysql/structures/methods/ping.js +0 -11
  45. package/database/mysql/structures/methods/process.js +0 -7
  46. package/database/mysql/structures/methods/pull.js +0 -23
  47. package/database/mysql/structures/methods/push.js +0 -23
  48. package/database/mysql/structures/methods/query.js +0 -9
  49. package/database/mysql/structures/methods/rename.js +0 -16
  50. package/database/mysql/structures/methods/set.js +0 -60
  51. package/database/mysql/structures/methods/stats.js +0 -13
  52. package/database/mysql/structures/methods/sub.js +0 -19
  53. package/database/mysql/structures/methods/tables.js +0 -8
  54. package/database/mysql/structures/methods/variables.js +0 -20
  55. package/database/newMongoDB/index.js +0 -94
  56. package/database/newMySQL/index.js +0 -205
  57. package/database/newSQLite/index.js +0 -240
  58. package/database/postgresql/index.js +0 -150
  59. package/database/redis/index.js +0 -125
  60. package/database/sqldb/index.js +0 -243
  61. package/database/yamldatabase/index.js +0 -76
  62. /package/database/{adapters/IDatabase.js → IDatabase.js} +0 -0
@@ -1,301 +0,0 @@
1
- const MySQL = require('../index.js'); // importing the package
2
-
3
- run();
4
- async function run(){
5
- const database = new MySQL(); // creates a database class
6
- let db = await database.connect({ // creates a connection for the database
7
- host: 'localhost',
8
- port: '3306', // the default port is 3306
9
- user: 'root',
10
- password: '',
11
- database: 'my_database',
12
- charset: 'utf8mb4',
13
- checkUpdates: true // checks for package updates
14
- }, true); // or you check for package updates here
15
-
16
- db.on('connected', async connection => { // database connected event
17
- console.log('Database Connected');
18
- });
19
-
20
- db.on('dataModification', async event => { // data changes & modifications event
21
- console.log(event);
22
- /*
23
- {
24
- oldData: 'bar',
25
- newData: 'bar2',
26
- type: 'UPDATE',
27
- table: 'test_table',
28
- modifiedAt: 1653815607288
29
- }
30
- */
31
- });
32
-
33
- db.on('tableCreate', async table => {
34
- console.log(`Table ${table} Created`);
35
- });
36
-
37
- db.on('tableDelete', async table => {
38
- console.log(`Table ${table} Deleted`);
39
- });
40
-
41
- db.on('tableClear', async table => {
42
- console.log(`Table ${table} Data Cleared`);
43
- });
44
-
45
- db.on('tableRename', async (oldName, newName) => {
46
- console.log(`Table renamed from ${oldName} to ${newName}`);
47
- });
48
-
49
- await db.set("my_table", "foo", "bar"); // stores 'bar' in 'foo' key name in the table 'my_table'
50
-
51
- let data = await db.get("my_table", "foo"); // gets foo key name value in the table 'my_table'
52
- console.log(data); // bar
53
-
54
- // you can also modify objects in all methods
55
- await db.set("my_table", "tariq.age", 14);
56
-
57
- data = await db.get("my_table", "tariq");
58
- console.log(data); // { age: 14 }
59
-
60
- data = await db.exists("my_table", "tq"); // checks if a specific data exists
61
- console.log(data); // false
62
-
63
- await db.base_set("my_table", "foo", "bar"); // stores 'bar' in 'foo' key name in the table 'my_table' but base encrypted
64
-
65
- data = await db.base_get("my_table", "foo"); // gets foo key name value in the table 'my_table' for encrypted rows using base_set method
66
- console.log(data); // bar
67
-
68
- await db.push("my_table", "array", "Value"); // pushs 'Value' to 'array' in 'my_table' table | or creates an array with 'Value' if not exists
69
- await db.push("my_table", "array", "Value");
70
- await db.push("my_table", "array", "Value2");
71
- let array = await db.push("my_table", "array", "Value2");
72
- console.log(array); // ['Value', 'Value', 'Value2', 'Value2']
73
-
74
- array = await db.pull("my_table", "array", "Value"); // pulls first 'Value' from 'array' in 'my_table'
75
- console.log(array); // ['Value', 'Value2', 'Value2']
76
-
77
- array = await db.pull("my_table", "array", "Value2", "all"); // pulls all 'Value2' from 'array' in 'my_table'
78
- console.log(array); // ['Value']
79
-
80
- let isExisted = await db.includes("my_table", "array", "Value"); // returns a boolean if array includes specific data
81
- console.log(isExisted); // true
82
-
83
- await db.add("my_table", "count", 10); // adds '10' to 'count' in 'my_table' table
84
-
85
- await db.sub("my_table", "count", 5); // subtracts '5' from 'count' in 'my_table' table
86
- // remaining count is 5
87
-
88
- let all = await db.all("my_table"); // gets all data in the table 'my_table'
89
- console.log(all);
90
- /*
91
- [
92
- {
93
- updated_at: 2021-06-26T17:10:05.000Z,
94
- created_at: 2021-06-26T17:10:05.000Z,
95
- ID: 'foo',
96
- data: 'bar'
97
- },
98
- {
99
- updated_at: 2021-06-26T17:10:05.000Z,
100
- created_at: 2021-06-26T17:10:05.000Z,
101
- ID: 'tariq',
102
- data: { age: 14 }
103
- },
104
- {
105
- updated_at: 2021-06-26T17:10:05.000Z,
106
- created_at: 2021-06-26T17:10:05.000Z,
107
- ID: 'array',
108
- data: [ 'Value' ]
109
- },
110
- {
111
- updated_at: 2021-06-26T17:10:05.000Z,
112
- created_at: 2021-06-26T17:10:05.000Z,
113
- ID: 'count',
114
- data: 5
115
- }
116
- ]
117
- */
118
-
119
- await db.delete("my_table", "foo"); // deletes foo row in the table 'my_table'
120
-
121
- let tables = await db.tables(); // gets array of all tables existed in the database
122
- console.log(tables); // ['my_table']
123
-
124
- await db.rename("my_table", "new_table"); // renames table name
125
-
126
- let stats = await db.stats("new_table"); // gets table info/stats
127
- console.log(stats);
128
- /*
129
- {
130
- Name: 'new_table',
131
- Engine: 'InnoDB',
132
- Version: 10,
133
- Row_format: 'Dynamic',
134
- Rows: 2,
135
- Avg_row_length: 8192,
136
- Data_length: 16384,
137
- Max_data_length: 0,
138
- Index_length: 0,
139
- Data_free: 0,
140
- Auto_increment: 5,
141
- Create_time: 2021-06-26T17:10:04.000Z,
142
- Update_time: 2021-06-26T17:10:05.000Z,
143
- Check_time: null,
144
- Collation: 'utf8mb4_general_ci',
145
- Checksum: null,
146
- Create_options: '',
147
- Comment: '',
148
- Max_index_length: 0,
149
- Temporary: 'N'
150
- }
151
- */
152
-
153
- await db.auto_increment("new_table", 5); // sets table auto increment to 5
154
-
155
- let response = await db.query("SELECT * from new_table;"); // executes a SQL query to the table
156
- console.log(response);
157
- /*
158
- [
159
- {
160
- id: 2,
161
- key_name: 'tariq',
162
- value: '{"age":14}',
163
- updated_at: 2021-06-26T17:10:05.000Z,
164
- created_at: 2021-06-26T17:10:05.000Z
165
- },
166
- {
167
- id: 3,
168
- key_name: 'array',
169
- value: '["Value"]',
170
- updated_at: 2021-06-26T17:10:05.000Z,
171
- created_at: 2021-06-26T17:10:05.000Z
172
- },
173
- {
174
- id: 4,
175
- key_name: 'count',
176
- value: '5',
177
- updated_at: 2021-06-26T17:10:05.000Z,
178
- created_at: 2021-06-26T17:10:05.000Z
179
- }
180
- ]
181
- */
182
-
183
- await db.create("table_name"); // creates table without inserting any data
184
- // note: store methods such as: (set,push,add,sub) creates the table automatically
185
-
186
- let ping = await db.ping(); // gets database ping (in ms)
187
- console.log(ping); // 27
188
-
189
- await db.clear("new_table"); // clear all table data
190
-
191
- // lastly delete the table
192
- await db.drop("new_table"); // drops/deletes the table
193
- await db.drop("table_name");
194
-
195
- await db.variables({ // modifies any global variable
196
- max_connections: 100000,
197
- max_connect_errors: 100000,
198
- wait_timeout: 60
199
- });
200
-
201
- let processList = await db.process(); // gets all active process list
202
- console.log(processList);
203
- /*
204
- [
205
- {
206
- Id: 2,
207
- User: 'system user',
208
- Host: '',
209
- db: null,
210
- Command: 'Daemon',
211
- Time: null,
212
- State: 'InnoDB purge worker',
213
- Info: null,
214
- Progress: 0
215
- },
216
- {
217
- Id: 3,
218
- User: 'system user',
219
- Host: '',
220
- db: null,
221
- Command: 'Daemon',
222
- Time: null,
223
- State: 'InnoDB purge worker',
224
- Info: null,
225
- Progress: 0
226
- },
227
- {
228
- Id: 4,
229
- User: 'system user',
230
- Host: '',
231
- db: null,
232
- Command: 'Daemon',
233
- Time: null,
234
- State: 'InnoDB purge worker',
235
- Info: null,
236
- Progress: 0
237
- },
238
- {
239
- Id: 1,
240
- User: 'system user',
241
- Host: '',
242
- db: null,
243
- Command: 'Daemon',
244
- Time: null,
245
- State: 'InnoDB purge coordinator',
246
- Info: null,
247
- Progress: 0
248
- },
249
- {
250
- Id: 5,
251
- User: 'system user',
252
- Host: '',
253
- db: null,
254
- Command: 'Daemon',
255
- Time: null,
256
- State: 'InnoDB shutdown handler',
257
- Info: null,
258
- Progress: 0
259
- },
260
- {
261
- Id: 253,
262
- User: 'root',
263
- Host: 'localhost:61146',
264
- db: 'my_database',
265
- Command: 'Query',
266
- Time: 0,
267
- State: 'Init',
268
- Info: 'SHOW PROCESSLIST',
269
- Progress: 0
270
- }
271
- ]
272
- */
273
-
274
- await db.create_db("second_db"); // creates a separate database on the server
275
-
276
- // you need to create a new connection manually after creating a new database
277
- const secondDB = new MySQL();
278
- let newDb = await secondDB.connect({
279
- host: 'localhost',
280
- port: '3306',
281
- user: 'root',
282
- password: '',
283
- database: 'second_db',
284
- charset: 'utf8mb4',
285
- });
286
- // note: if you had an old events, you need to re-register the events since this is a new class created
287
- newDb.on('connected', async connection => { // database connected event
288
- console.log('New Database Connected');
289
- });
290
-
291
- // now you can manage your "newDb" connection
292
- await newDb.set("second_db_table", "key", "value");
293
- await newDb.drop("second_db_table");
294
-
295
- // you can still manage your old "db" connection as well
296
- await db.set("old_db_table", "key", "value");
297
- await db.drop("old_db_table");
298
-
299
- await db.end(); // closes the connection
300
- await newDb.end();
301
- }
@@ -1 +0,0 @@
1
- module.exports = require('./structures/classes/MySQL');
@@ -1,41 +0,0 @@
1
- "use strict";
2
-
3
- const EventEmitter = require("events");
4
- const getAllData = require("../methods/getAllData");
5
-
6
- module.exports = class MySQL extends EventEmitter {
7
- constructor() {
8
- super();
9
- }
10
- name = "FxesDbMySQL";
11
- version = "1.0.0";
12
- connect = require("../methods/connect");
13
- getAllData = getAllData;
14
- query = require("../methods/query");
15
- get = require("../methods/get");
16
- set = require("../methods/set");
17
- push = require("../methods/push");
18
- includes = require("../methods/includes");
19
- pull = require("../methods/pull");
20
- add = require("../methods/add");
21
- sub = require("../methods/sub");
22
- subtract = require("../methods/sub");
23
- delete = require("../methods/delete");
24
- all = require("../methods/all");
25
- tables = require("../methods/tables");
26
- rename = require("../methods/rename");
27
- stats = require("../methods/stats");
28
- auto_increment = require("../methods/auto_increment");
29
- create = require("../methods/create");
30
- drop = require("../methods/drop");
31
- variables = require("../methods/variables");
32
- process = require("../methods/process");
33
- ping = require("../methods/ping");
34
- clear = require("../methods/clear");
35
- base_set = require("../methods/base_set");
36
- base_get = require("../methods/base_get");
37
- end = require("../methods/end");
38
- exists = require("../methods/exists");
39
- create_db = require("../methods/create_db");
40
- has = require("../methods/has");
41
- };
@@ -1,23 +0,0 @@
1
- module.exports = {
2
- "table": "Table was not specified in function arguments or not string, received {received}",
3
- "key": "Key was not specified in function arguments or not string, received {received}",
4
- "value": "Value was not specified in function arguments, received {received}",
5
- "number": "Number was not specified in function arguments or not number, received {received}",
6
- "numberType": "Number argument must be an positive integer, received {received}",
7
- "query": "SQL Query was not specified in function arguments or not string, received {received}",
8
- "databaseName": "Database name was not specified in function arguments or not string, received {received}",
9
-
10
- "array": "{key} key's value is not an array",
11
- "notNumber": "{key} key's value is not a number",
12
- "dataNotFound": "Data with the key {key} was not found",
13
- "tableNotFound": "Table with the name {table} does not exist",
14
- "tableAlreadyExists": "Table with the name {table} already exists",
15
- "tableRenameSameName": "Can't rename a table to its current name",
16
-
17
- "targetNotObject": "Cannot target a non-object with the key {key}",
18
- "variables": "Variables object argument was not specified in function arguments, received {received}",
19
- "variablesNotObject": "Variables argument is not an object, received {received}",
20
- "noTablesExisted": "No tables existed to get database ping, at least one table must be existed in the database",
21
-
22
- "baseNotString": "Base functions only works for strings"
23
- }
@@ -1,19 +0,0 @@
1
- "use strict";
2
-
3
- const errors = require("../errors/strings.js");
4
-
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,25 +0,0 @@
1
- "use strict";
2
-
3
- const errors = require("../errors/strings.js");
4
-
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,16 +0,0 @@
1
- "use strict";
2
-
3
- const errors = require("../errors/strings.js");
4
-
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,14 +0,0 @@
1
- "use strict";
2
-
3
- const errors = require("../errors/strings.js");
4
-
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,21 +0,0 @@
1
- "use strict";
2
-
3
- const errors = require("../errors/strings.js");
4
-
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,16 +0,0 @@
1
- "use strict";
2
-
3
- const errors = require("../errors/strings.js");
4
-
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,15 +0,0 @@
1
- "use strict";
2
-
3
- const mysql = require('promise-mysql');
4
- const errors = require('../errors/strings.js');
5
-
6
-
7
- module.exports = async function(options, checkUpdates){
8
- let me = this;
9
- me.db = await mysql.createPool(options);
10
- me.db.pool.getConnection((err,connection) => {
11
- if(err) throw err;
12
- me.emit("connected", connection);
13
- });
14
- return me;
15
- }
@@ -1,11 +0,0 @@
1
- "use strict";
2
-
3
- const errors = require('../errors/strings.js');
4
-
5
- module.exports = async function(table, isClear){
6
- if(!table || typeof table !== "string") throw new TypeError(errors.table.replace("{received}", typeof table));
7
-
8
- await this.query('CREATE TABLE IF NOT EXISTS `' + table + '` (`id` int(11) NOT NULL auto_increment, `key_name` LONGTEXT NULL, `value` LONGTEXT NULL, `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`))');
9
- if(!isClear) this.emit("tableCreate", table);
10
- return true;
11
- }
@@ -1,10 +0,0 @@
1
- "use strict";
2
-
3
- const errors = require('../errors/strings.js');
4
-
5
- module.exports = async function(dbName){
6
- if(!dbName || typeof dbName !== "string") throw new TypeError(errors.databaseName.replace("{received}", typeof table));
7
-
8
- await this.db.query(`CREATE DATABASE IF NOT EXISTS \`${dbName}\``);
9
- return true;
10
- }
@@ -1,31 +0,0 @@
1
- "use strict";
2
-
3
- const unset = require("lodash/unset");
4
- const errors = require("../errors/strings.js");
5
-
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 +0,0 @@
1
- "use strict";
2
-
3
- const errors = require('../errors/strings.js');
4
-
5
- module.exports = async function(table, isClear){
6
- if(!table || typeof table !== "string") throw new TypeError(errors.table.replace("{received}", typeof table));
7
-
8
- let tables = await this.tables();
9
- if(!tables.includes(table)) return false;
10
- await this.db.query(`DROP TABLE \`${table}\``);
11
- if(tables.includes(table) && !isClear) this.emit("tableDelete", table);
12
- return true;
13
- }
@@ -1,7 +0,0 @@
1
- "use strict";
2
-
3
- const errors = require('../errors/strings.js');
4
-
5
- module.exports = async function(){
6
- return this.db.end();
7
- }
@@ -1,15 +0,0 @@
1
- "use strict";
2
-
3
- const errors = require("../errors/strings.js");
4
-
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 +0,0 @@
1
- "use strict";
2
-
3
- const get = require("lodash/get");
4
- const errors = require("../errors/strings.js");
5
-
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,35 +0,0 @@
1
- "use strict";
2
-
3
- const errors = require("../errors/strings.js");
4
-
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
-
10
- // Tabloları kontrol et
11
- let tables = await this.tables();
12
- if (!tables.includes(table)) {
13
- throw new TypeError(errors.tableNotFound.replace("{table}", table));
14
- }
15
-
16
- // Tüm verileri al
17
- let all = await this.query(`SELECT key_name, value FROM \`${table}\``);
18
- let result = {};
19
-
20
- all.forEach((row) => {
21
- let key = row.key_name;
22
- let value = row.value;
23
-
24
- // JSON parse işlemi
25
- try {
26
- value = JSON.parse(value);
27
- } catch (e) {
28
- // JSON değilse olduğu gibi bırak
29
- }
30
-
31
- result[key] = value;
32
- });
33
-
34
- return result;
35
- };