sehawq.db 4.0.3 → 4.0.5
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/.github/workflows/npm-publish.yml +30 -30
- package/LICENSE +21 -21
- package/index.js +1 -1
- package/package.json +36 -36
- package/readme.md +413 -413
- package/src/core/Database.js +294 -294
- package/src/core/Events.js +285 -285
- package/src/core/IndexManager.js +813 -813
- package/src/core/Persistence.js +375 -375
- package/src/core/QueryEngine.js +447 -447
- package/src/core/Storage.js +321 -321
- package/src/core/Validator.js +324 -324
- package/src/index.js +115 -115
- package/src/performance/Cache.js +338 -338
- package/src/performance/LazyLoader.js +354 -354
- package/src/performance/MemoryManager.js +495 -495
- package/src/server/api.js +687 -687
- package/src/server/websocket.js +527 -527
- package/src/utils/benchmark.js +51 -51
- package/src/utils/dot-notation.js +247 -247
- package/src/utils/helpers.js +275 -275
- package/src/utils/profiler.js +70 -70
- package/src/version.js +37 -37
package/src/index.js
CHANGED
|
@@ -1,116 +1,116 @@
|
|
|
1
|
-
// src/index.js - The heart of SehawqDB v4.0.0
|
|
2
|
-
const Database = require('./core/Database');
|
|
3
|
-
const QueryEngine = require('./core/QueryEngine');
|
|
4
|
-
const IndexManager = require('./core/IndexManager');
|
|
5
|
-
const Storage = require('./core/Storage');
|
|
6
|
-
|
|
7
|
-
class SehawqDB {
|
|
8
|
-
constructor(options = {}) {
|
|
9
|
-
this.database = new Database(options);
|
|
10
|
-
this.queryEngine = new QueryEngine(this.database);
|
|
11
|
-
this.indexManager = new IndexManager(this.database, options);
|
|
12
|
-
|
|
13
|
-
// Database methods
|
|
14
|
-
this.set = this.database.set.bind(this.database);
|
|
15
|
-
this.get = this.database.get.bind(this.database);
|
|
16
|
-
this.delete = this.database.delete.bind(this.database);
|
|
17
|
-
this.has = this.database.has.bind(this.database);
|
|
18
|
-
this.all = this.database.all.bind(this.database);
|
|
19
|
-
this.clear = this.database.clear.bind(this.database);
|
|
20
|
-
|
|
21
|
-
// 🔥 Query methods
|
|
22
|
-
this.find = this.queryEngine.find.bind(this.queryEngine);
|
|
23
|
-
this.where = this.queryEngine.where.bind(this.queryEngine);
|
|
24
|
-
this.findAll = this.queryEngine.findAll.bind(this.queryEngine);
|
|
25
|
-
this.count = this.queryEngine.count.bind(this.queryEngine);
|
|
26
|
-
this.sum = this.queryEngine.sum.bind(this.queryEngine);
|
|
27
|
-
this.avg = this.queryEngine.avg.bind(this.queryEngine);
|
|
28
|
-
this.min = this.queryEngine.min.bind(this.queryEngine);
|
|
29
|
-
this.max = this.queryEngine.max.bind(this.queryEngine);
|
|
30
|
-
this.groupBy = this.queryEngine.groupBy.bind(this.queryEngine);
|
|
31
|
-
|
|
32
|
-
// 🔥 Index methods
|
|
33
|
-
this.createIndex = this.indexManager.createIndex.bind(this.indexManager);
|
|
34
|
-
this.dropIndex = this.indexManager.dropIndex.bind(this.indexManager);
|
|
35
|
-
this.getIndexes = this.indexManager.getIndexes.bind(this.indexManager);
|
|
36
|
-
|
|
37
|
-
// 🔥 ARRAY & MATH Methods
|
|
38
|
-
this.push = this.database.push?.bind(this.database) || this._fallbackPush.bind(this);
|
|
39
|
-
this.pull = this.database.pull?.bind(this.database) || this._fallbackPull.bind(this);
|
|
40
|
-
this.add = this.database.add?.bind(this.database) || this._fallbackAdd.bind(this);
|
|
41
|
-
this.subtract = this.database.subtract?.bind(this.database) || this._fallbackSubtract.bind(this);
|
|
42
|
-
|
|
43
|
-
// 🔥 BACKUP & RESTORE Methods
|
|
44
|
-
this.backup = this.database.backup?.bind(this.database) || this._fallbackBackup.bind(this);
|
|
45
|
-
this.restore = this.database.restore?.bind(this.database) || this._fallbackRestore.bind(this);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// 🔥 FALLBACK Methods
|
|
49
|
-
_fallbackPush(key, value) {
|
|
50
|
-
const array = this.get(key) || [];
|
|
51
|
-
array.push(value);
|
|
52
|
-
this.set(key, array);
|
|
53
|
-
return array.length;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
_fallbackPull(key, value) {
|
|
57
|
-
const array = this.get(key) || [];
|
|
58
|
-
const index = array.indexOf(value);
|
|
59
|
-
if (index > -1) {
|
|
60
|
-
array.splice(index, 1);
|
|
61
|
-
this.set(key, array);
|
|
62
|
-
return true;
|
|
63
|
-
}
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
_fallbackAdd(key, number) {
|
|
68
|
-
const current = this.get(key) || 0;
|
|
69
|
-
const newValue = current + number;
|
|
70
|
-
this.set(key, newValue);
|
|
71
|
-
return newValue;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
_fallbackSubtract(key, number) {
|
|
75
|
-
return this._fallbackAdd(key, -number);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// 🔥 BACKUP FALLBACK Methods
|
|
79
|
-
async _fallbackBackup(backupPath = null) {
|
|
80
|
-
const path = backupPath || `./sehawq-backup-${Date.now()}.json`;
|
|
81
|
-
const storage = new Storage(path);
|
|
82
|
-
const data = this.all();
|
|
83
|
-
await storage.write(data);
|
|
84
|
-
return path;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
async _fallbackRestore(backupPath) {
|
|
88
|
-
const storage = new Storage(backupPath);
|
|
89
|
-
const data = await storage.read();
|
|
90
|
-
this.clear();
|
|
91
|
-
for (const [key, value] of Object.entries(data)) {
|
|
92
|
-
this.set(key, value);
|
|
93
|
-
}
|
|
94
|
-
return true;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
async start() {
|
|
98
|
-
await new Promise(resolve => this.database.on('ready', resolve));
|
|
99
|
-
return this;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
async stop() {
|
|
103
|
-
await this.database.close();
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// 🔥 STATS Methods
|
|
107
|
-
getStats() {
|
|
108
|
-
return {
|
|
109
|
-
database: this.database.getStats?.(),
|
|
110
|
-
query: this.queryEngine.getStats?.(),
|
|
111
|
-
indexes: this.indexManager.getStats?.()
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
1
|
+
// src/index.js - The heart of SehawqDB v4.0.0
|
|
2
|
+
const Database = require('./core/Database');
|
|
3
|
+
const QueryEngine = require('./core/QueryEngine');
|
|
4
|
+
const IndexManager = require('./core/IndexManager');
|
|
5
|
+
const Storage = require('./core/Storage');
|
|
6
|
+
|
|
7
|
+
class SehawqDB {
|
|
8
|
+
constructor(options = {}) {
|
|
9
|
+
this.database = new Database(options);
|
|
10
|
+
this.queryEngine = new QueryEngine(this.database);
|
|
11
|
+
this.indexManager = new IndexManager(this.database, options);
|
|
12
|
+
|
|
13
|
+
// Database methods
|
|
14
|
+
this.set = this.database.set.bind(this.database);
|
|
15
|
+
this.get = this.database.get.bind(this.database);
|
|
16
|
+
this.delete = this.database.delete.bind(this.database);
|
|
17
|
+
this.has = this.database.has.bind(this.database);
|
|
18
|
+
this.all = this.database.all.bind(this.database);
|
|
19
|
+
this.clear = this.database.clear.bind(this.database);
|
|
20
|
+
|
|
21
|
+
// 🔥 Query methods
|
|
22
|
+
this.find = this.queryEngine.find.bind(this.queryEngine);
|
|
23
|
+
this.where = this.queryEngine.where.bind(this.queryEngine);
|
|
24
|
+
this.findAll = this.queryEngine.findAll.bind(this.queryEngine);
|
|
25
|
+
this.count = this.queryEngine.count.bind(this.queryEngine);
|
|
26
|
+
this.sum = this.queryEngine.sum.bind(this.queryEngine);
|
|
27
|
+
this.avg = this.queryEngine.avg.bind(this.queryEngine);
|
|
28
|
+
this.min = this.queryEngine.min.bind(this.queryEngine);
|
|
29
|
+
this.max = this.queryEngine.max.bind(this.queryEngine);
|
|
30
|
+
this.groupBy = this.queryEngine.groupBy.bind(this.queryEngine);
|
|
31
|
+
|
|
32
|
+
// 🔥 Index methods
|
|
33
|
+
this.createIndex = this.indexManager.createIndex.bind(this.indexManager);
|
|
34
|
+
this.dropIndex = this.indexManager.dropIndex.bind(this.indexManager);
|
|
35
|
+
this.getIndexes = this.indexManager.getIndexes.bind(this.indexManager);
|
|
36
|
+
|
|
37
|
+
// 🔥 ARRAY & MATH Methods
|
|
38
|
+
this.push = this.database.push?.bind(this.database) || this._fallbackPush.bind(this);
|
|
39
|
+
this.pull = this.database.pull?.bind(this.database) || this._fallbackPull.bind(this);
|
|
40
|
+
this.add = this.database.add?.bind(this.database) || this._fallbackAdd.bind(this);
|
|
41
|
+
this.subtract = this.database.subtract?.bind(this.database) || this._fallbackSubtract.bind(this);
|
|
42
|
+
|
|
43
|
+
// 🔥 BACKUP & RESTORE Methods
|
|
44
|
+
this.backup = this.database.backup?.bind(this.database) || this._fallbackBackup.bind(this);
|
|
45
|
+
this.restore = this.database.restore?.bind(this.database) || this._fallbackRestore.bind(this);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 🔥 FALLBACK Methods
|
|
49
|
+
_fallbackPush(key, value) {
|
|
50
|
+
const array = this.get(key) || [];
|
|
51
|
+
array.push(value);
|
|
52
|
+
this.set(key, array);
|
|
53
|
+
return array.length;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
_fallbackPull(key, value) {
|
|
57
|
+
const array = this.get(key) || [];
|
|
58
|
+
const index = array.indexOf(value);
|
|
59
|
+
if (index > -1) {
|
|
60
|
+
array.splice(index, 1);
|
|
61
|
+
this.set(key, array);
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
_fallbackAdd(key, number) {
|
|
68
|
+
const current = this.get(key) || 0;
|
|
69
|
+
const newValue = current + number;
|
|
70
|
+
this.set(key, newValue);
|
|
71
|
+
return newValue;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
_fallbackSubtract(key, number) {
|
|
75
|
+
return this._fallbackAdd(key, -number);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// 🔥 BACKUP FALLBACK Methods
|
|
79
|
+
async _fallbackBackup(backupPath = null) {
|
|
80
|
+
const path = backupPath || `./sehawq-backup-${Date.now()}.json`;
|
|
81
|
+
const storage = new Storage(path);
|
|
82
|
+
const data = this.all();
|
|
83
|
+
await storage.write(data);
|
|
84
|
+
return path;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async _fallbackRestore(backupPath) {
|
|
88
|
+
const storage = new Storage(backupPath);
|
|
89
|
+
const data = await storage.read();
|
|
90
|
+
this.clear();
|
|
91
|
+
for (const [key, value] of Object.entries(data)) {
|
|
92
|
+
this.set(key, value);
|
|
93
|
+
}
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async start() {
|
|
98
|
+
await new Promise(resolve => this.database.on('ready', resolve));
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async stop() {
|
|
103
|
+
await this.database.close();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// 🔥 STATS Methods
|
|
107
|
+
getStats() {
|
|
108
|
+
return {
|
|
109
|
+
database: this.database.getStats?.(),
|
|
110
|
+
query: this.queryEngine.getStats?.(),
|
|
111
|
+
indexes: this.indexManager.getStats?.()
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
116
|
module.exports = { SehawqDB };
|