@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,243 +0,0 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const sqlite3 = require("sqlite3").verbose();
4
-
5
- class Database {
6
- constructor(dbFilePath) {
7
- this.dbFilePath = dbFilePath || path.join(__dirname, "database.sqlite");
8
- this.db = null;
9
-
10
- // Veritabanı hazır olana kadar işlemleri bekletmek için bir Promise
11
- this.ready = new Promise((resolve, reject) => {
12
- if (!fs.existsSync(this.dbFilePath)) {
13
- console.log("Database file does not exist. Creating the file...");
14
- fs.writeFileSync(this.dbFilePath, ""); // Boş bir dosya oluştur
15
- }
16
-
17
- // Veritabanını başlat
18
- this.db = new sqlite3.Database(this.dbFilePath, (err) => {
19
- if (err) {
20
- console.error("Error opening database:", err.message);
21
- reject(err);
22
- } else {
23
- console.log("Connected to the SQLite database.");
24
- this.runQuery(
25
- `CREATE TABLE IF NOT EXISTS key_value_store (key TEXT PRIMARY KEY, value TEXT)`
26
- )
27
- .then(() => {
28
- console.log("Table initialized");
29
- resolve(); // Veritabanı hazır
30
- })
31
- .catch((err) => {
32
- console.error(err);
33
- reject(err);
34
- });
35
- }
36
- });
37
- });
38
- }
39
-
40
- _ensureDatabaseInitialized() {
41
- if (!this.db) {
42
- throw new Error(
43
- "Database is not initialized. Ensure the database file exists."
44
- );
45
- }
46
- }
47
-
48
- _parseNestedKey(key) {
49
- return key.includes(".") ? key.split(".") : [key];
50
- }
51
-
52
- _buildNestedObject(keys, value) {
53
- return keys.reverse().reduce((acc, curr) => ({ [curr]: acc }), value);
54
- }
55
-
56
- _mergeObjects(target, source) {
57
- for (const key in source) {
58
- if (source[key] instanceof Object && key in target) {
59
- Object.assign(
60
- source[key],
61
- this._mergeObjects(target[key], source[key])
62
- );
63
- }
64
- }
65
- return { ...target, ...source };
66
- }
67
-
68
- async set(key, value) {
69
- await this.ready; // Veritabanı hazır olana kadar bekle
70
- this._ensureDatabaseInitialized();
71
- const keys = this._parseNestedKey(key);
72
- if (keys.length > 1) {
73
- return this.get(keys[0]).then((currentValue) => {
74
- const nestedObject = this._buildNestedObject(keys.slice(1), value);
75
- const mergedValue = this._mergeObjects(
76
- currentValue || {},
77
- nestedObject
78
- );
79
- return this.set(keys[0], mergedValue);
80
- });
81
- }
82
-
83
- return this.runQuery(
84
- `INSERT INTO key_value_store (key, value) VALUES (?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value`,
85
- [key, JSON.stringify(value)]
86
- );
87
- }
88
-
89
- async get(key) {
90
- await this.ready; // Veritabanı hazır olana kadar bekle
91
- this._ensureDatabaseInitialized();
92
- const keys = this._parseNestedKey(key);
93
- return this.getQuery(`SELECT value FROM key_value_store WHERE key = ?`, [
94
- keys[0],
95
- ]).then((row) => {
96
- if (!row) return null;
97
- const value = JSON.parse(row.value);
98
- return keys.length > 1
99
- ? keys.slice(1).reduce((acc, curr) => (acc ? acc[curr] : null), value)
100
- : value;
101
- });
102
- }
103
-
104
- async delete(key) {
105
- await this.ready; // Veritabanı hazır olana kadar bekle
106
- this._ensureDatabaseInitialized();
107
- const keys = this._parseNestedKey(key);
108
- if (keys.length > 1) {
109
- return this.get(keys[0]).then((currentValue) => {
110
- if (!currentValue) return null;
111
- let ref = currentValue;
112
- for (let i = 0; i < keys.length - 1; i++) {
113
- if (!ref[keys[i]]) return null;
114
- if (i === keys.length - 2) {
115
- delete ref[keys[i + 1]];
116
- } else {
117
- ref = ref[keys[i]];
118
- }
119
- }
120
- return this.set(keys[0], currentValue);
121
- });
122
- }
123
- return this.runQuery(`DELETE FROM key_value_store WHERE key = ?`, [key]);
124
- }
125
-
126
- async has(key) {
127
- await this.ready;
128
- let result = undefined; // Veritabanı hazır olana kadar bekle
129
- await this.get(key).then((value) => (result = value));
130
- if (!result) return false;
131
- else {
132
- return true;
133
- }
134
- }
135
-
136
- async push(key, value) {
137
- await this.ready; // Veritabanı hazır olana kadar bekle
138
- return this.get(key).then((currentValue) => {
139
- if (!Array.isArray(currentValue)) {
140
- currentValue = [];
141
- }
142
- currentValue.push(value);
143
- return this.set(key, currentValue);
144
- });
145
- }
146
-
147
- async add(key, value) {
148
- await this.ready; // Veritabanı hazır olana kadar bekle
149
- return this.get(key).then((currentValue) => {
150
- if (typeof currentValue !== "number") {
151
- currentValue = 0;
152
- }
153
- return this.set(key, currentValue + value);
154
- });
155
- }
156
-
157
- async sub(key, value) {
158
- await this.ready; // Veritabanı hazır olana kadar bekle
159
- return this.get(key).then((currentValue) => {
160
- if (typeof currentValue !== "number") {
161
- currentValue = 0;
162
- }
163
- return this.set(key, currentValue - value);
164
- });
165
- }
166
-
167
- runQuery(query, params = []) {
168
- return new Promise((resolve, reject) => {
169
- this.db.run(query, params, function (err) {
170
- if (err) {
171
- reject(err);
172
- } else {
173
- resolve(this);
174
- }
175
- });
176
- });
177
- }
178
-
179
- getQuery(query, params = []) {
180
- return new Promise((resolve, reject) => {
181
- this.db.get(query, params, (err, row) => {
182
- if (err) {
183
- reject(err);
184
- } else {
185
- resolve(row);
186
- }
187
- });
188
- });
189
- }
190
- async getAllData() {
191
- await this.ready; // Veritabanı hazır olana kadar bekle
192
- this._ensureDatabaseInitialized();
193
-
194
- return new Promise((resolve, reject) => {
195
- this.db.all(`SELECT key, value FROM key_value_store`, [], (err, rows) => {
196
- if (err) {
197
- console.error("Error fetching all data:", err.message);
198
- return reject(err);
199
- }
200
-
201
- const result = {};
202
- rows.forEach((row) => {
203
- let value = row.value;
204
-
205
- // JSON parse işlemi
206
- try {
207
- value = JSON.parse(value);
208
- } catch (e) {
209
- // JSON değilse olduğu gibi bırak
210
- }
211
-
212
- result[row.key] = value;
213
- });
214
-
215
- resolve(result);
216
- });
217
- });
218
- }
219
- close() {
220
- if (this.db) {
221
- this.db.close((err) => {
222
- if (err) {
223
- console.error("Error closing database:", err.message);
224
- } else {
225
- console.log("Database connection closed.");
226
- }
227
- });
228
- }
229
- }
230
- }
231
-
232
- module.exports = Database;
233
-
234
- // Example usage:
235
- // const db = new Database();
236
- // db.set('foo.bar.baz', 'value')
237
- // .then(() => db.get('foo.bar'))
238
- // .then((value) => console.log('Value:', value)) // Output: { baz: 'value' }
239
- // .then(() => db.delete('foo.bar.baz'))
240
- // .then(() => db.get('foo'))
241
- // .then((value) => console.log('After delete:', value)) // Output: {}
242
- // .catch((err) => console.error(err))
243
- // .finally(() => db.close());
@@ -1,76 +0,0 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const yaml = require("js-yaml");
4
-
5
- class YAMLDatabase {
6
- constructor(filePath) {
7
- this.filePath = filePath || path.join(__dirname, "database.yaml");
8
- if (!fs.existsSync(this.filePath)) {
9
- fs.writeFileSync(this.filePath, yaml.dump({}));
10
- }
11
- }
12
-
13
- _readYAML() {
14
- const data = fs.readFileSync(this.filePath, "utf8");
15
- return yaml.load(data) || {};
16
- }
17
-
18
- _writeYAML(data) {
19
- fs.writeFileSync(this.filePath, yaml.dump(data));
20
- }
21
-
22
- async set(key, value) {
23
- const data = this._readYAML();
24
- data[key] = value;
25
- this._writeYAML(data);
26
- }
27
-
28
- async get(key) {
29
- const data = this._readYAML();
30
- return data[key] || null;
31
- }
32
-
33
- async delete(key) {
34
- const data = this._readYAML();
35
- delete data[key];
36
- this._writeYAML(data);
37
- }
38
-
39
- async has(key) {
40
- const data = this._readYAML();
41
- return key in data;
42
- }
43
-
44
- async push(key, value) {
45
- const data = this._readYAML();
46
- if (!Array.isArray(data[key])) {
47
- data[key] = [];
48
- }
49
- data[key].push(value);
50
- this._writeYAML(data);
51
- }
52
-
53
- async add(key, value) {
54
- const data = this._readYAML();
55
- if (typeof data[key] !== "number") {
56
- data[key] = 0;
57
- }
58
- data[key] += value;
59
- this._writeYAML(data);
60
- }
61
-
62
- async sub(key, value) {
63
- const data = this._readYAML();
64
- if (typeof data[key] !== "number") {
65
- data[key] = 0;
66
- }
67
- data[key] -= value;
68
- this._writeYAML(data);
69
- }
70
-
71
- async getAllData() {
72
- return this._readYAML();
73
- }
74
- }
75
-
76
- module.exports = YAMLDatabase;