@wowoengine/sawitdb 2.4.0 → 2.5.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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "2.4.0",
6
+ "version": "2.5.0",
7
7
  "description": "A networked document database with Indonesian Agricultural Query Language (AQL) - Network Edition",
8
8
  "main": "src/WowoEngine.js",
9
9
  "scripts": {
@@ -35,6 +35,8 @@ class SawitServer {
35
35
 
36
36
  this._log('info', `Data directory: ${this.dataDir}`);
37
37
  this._log('info', `Max connections: ${this.maxConnections}`);
38
+
39
+ this.walConfig = config.wal || { enabled: false };
38
40
  }
39
41
 
40
42
  _validatePort(port) {
@@ -65,7 +67,7 @@ class SawitServer {
65
67
 
66
68
  this.server.listen(this.port, this.host, () => {
67
69
  console.log(`╔══════════════════════════════════════════════════╗`);
68
- console.log(`║ 🌴 SawitDB Server - Version 2.4 ║`);
70
+ console.log(`║ 🌴 SawitDB Server - Version 2.5.0 ║`);
69
71
  console.log(`╚══════════════════════════════════════════════════╝`);
70
72
  console.log(`[Server] Listening on ${this.host}:${this.port}`);
71
73
  console.log(`[Server] Protocol: sawitdb://${this.host}:${this.port}/[database]`);
@@ -85,6 +87,17 @@ class SawitServer {
85
87
  client.destroy();
86
88
  }
87
89
 
90
+ // Close all open databases to release file locks
91
+ for (const [name, db] of this.databases) {
92
+ try {
93
+ console.log(`[Server] Closing database: ${name}`);
94
+ db.close();
95
+ } catch (e) {
96
+ console.error(`[Server] Error closing database ${name}:`, e.message);
97
+ }
98
+ }
99
+ this.databases.clear();
100
+
88
101
  // Close server
89
102
  if (this.server) {
90
103
  this.server.close(() => {
@@ -181,7 +194,7 @@ class SawitServer {
181
194
  this._sendResponse(socket, {
182
195
  type: 'welcome',
183
196
  message: 'SawitDB Server',
184
- version: '2.4',
197
+ version: '2.5.0',
185
198
  protocol: 'sawitdb'
186
199
  });
187
200
  }
@@ -402,29 +415,30 @@ class SawitServer {
402
415
  }
403
416
  const dbName = parts[2];
404
417
 
405
- // Reuse existing logic
406
- const payload = { database: dbName };
407
- // We need to adapt the existing _handleDropDatabase to generic usage or call it.
408
- // _handleDropDatabase sends its own response. We want query_result format preferably for consistency in CLI?
409
- // The existing _handleDropDatabase sends 'drop_success'. CLI might not print that as a query result string.
410
- // Let's reimplement logic here for 'query' flow to ensure 'query_result' type.
411
-
412
418
  try {
413
419
  const dbPath = path.join(this.dataDir, `${dbName}.sawit`);
414
420
  if (!fs.existsSync(dbPath)) {
415
421
  return this._sendError(socket, `Wilayah '${dbName}' tidak ditemukan.`);
416
422
  }
417
423
 
424
+ // FIX: Close database before deletion to release file lock
418
425
  if (this.databases.has(dbName)) {
426
+ const db = this.databases.get(dbName);
427
+ try { db.close(); } catch (e) { }
419
428
  this.databases.delete(dbName);
420
429
  }
421
430
 
422
- try { fs.unlinkSync(dbPath); } catch (e) { }
423
-
431
+ // If current user is in this db, kick them out
424
432
  if (context.currentDatabase === dbName) {
425
433
  context.setDatabase(null);
426
434
  }
427
435
 
436
+ try { fs.unlinkSync(dbPath); } catch (e) {
437
+ // Retry once after short delay if locked? Or just throw.
438
+ // If close() works, this should succeed.
439
+ throw e;
440
+ }
441
+
428
442
  return this._sendResponse(socket, {
429
443
  type: 'query_result',
430
444
  result: `Wilayah '${dbName}' telah hangus terbakar.`,
@@ -531,6 +545,7 @@ class SawitServer {
531
545
 
532
546
  // Close database if open
533
547
  if (this.databases.has(database)) {
548
+ this.databases.get(database).close(); // Fix: Close first
534
549
  this.databases.delete(database);
535
550
  }
536
551
 
@@ -555,7 +570,7 @@ class SawitServer {
555
570
  _getOrCreateDatabase(name) {
556
571
  if (!this.databases.has(name)) {
557
572
  const dbPath = path.join(this.dataDir, `${name}.sawit`);
558
- const db = new SawitDB(dbPath);
573
+ const db = new SawitDB(dbPath, { wal: this.walConfig });
559
574
  this.databases.set(name, db);
560
575
  }
561
576
  return this.databases.get(name);