jexidb 2.0.2 โ 2.0.3
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/CHANGELOG.md +109 -0
- package/README.md +119 -7
- package/dist/JSONLDatabase.js +240 -101
- package/docs/API.md +390 -0
- package/docs/EXAMPLES.md +177 -0
- package/docs/MIGRATION.md +295 -0
- package/docs/README.md +184 -0
- package/examples/auto-save-example.js +158 -0
- package/examples/cjs-usage.cjs +82 -0
- package/examples/close-vs-delete-example.js +71 -0
- package/examples/esm-usage.js +113 -0
- package/examples/example-columns.idx.jdb +0 -0
- package/examples/example-columns.jdb +9 -0
- package/examples/example-options.idx.jdb +0 -0
- package/examples/example-options.jdb +0 -0
- package/examples/example-users.idx.jdb +0 -0
- package/examples/example-users.jdb +5 -0
- package/examples/simple-test.js +55 -0
- package/package.json +5 -2
- package/src/JSONLDatabase.js +245 -102
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to JexiDB will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [2.0.3] - 2024-12-19
|
|
9
|
+
|
|
10
|
+
### ๐ Added
|
|
11
|
+
- **Intelligent Auto-Save System**: Automatic data persistence with configurable thresholds and intervals
|
|
12
|
+
- `autoSaveThreshold`: Flush buffer when it reaches N records (default: 50)
|
|
13
|
+
- `autoSaveInterval`: Flush buffer every N milliseconds (default: 5000ms)
|
|
14
|
+
- `forceSaveOnClose`: Always save when closing database (default: true)
|
|
15
|
+
- **New Public Methods**:
|
|
16
|
+
- `flush()`: Explicitly flush insertion buffer to disk
|
|
17
|
+
- `forceSave()`: Force save operation regardless of buffer size
|
|
18
|
+
- `getBufferStatus()`: Get current buffer state information
|
|
19
|
+
- `configurePerformance(settings)`: Dynamic performance configuration
|
|
20
|
+
- `getPerformanceConfig()`: Get current performance settings
|
|
21
|
+
- `deleteDatabase()`: Permanently delete database file
|
|
22
|
+
- `removeDatabase()`: Alias for deleteDatabase()
|
|
23
|
+
- **Event-Driven Monitoring**: New events for auto-save operations
|
|
24
|
+
- `buffer-flush`: Emitted when buffer is flushed
|
|
25
|
+
- `buffer-full`: Emitted when buffer reaches threshold
|
|
26
|
+
- `auto-save-timer`: Emitted when time-based auto-save triggers
|
|
27
|
+
- `save-complete`: Emitted when save operation completes
|
|
28
|
+
- `close-save-complete`: Emitted when database closes with final save
|
|
29
|
+
- `performance-configured`: Emitted when performance settings change
|
|
30
|
+
- `delete-database`: Emitted when database file is deleted
|
|
31
|
+
- **Performance Configuration Options**:
|
|
32
|
+
- `adaptiveBatchSize`: Adjust batch size based on usage (default: true)
|
|
33
|
+
- `minBatchSize`: Minimum batch size for flush (default: 10)
|
|
34
|
+
- `maxBatchSize`: Maximum batch size for performance (default: 200)
|
|
35
|
+
- `maxMemoryUsage`: Memory usage limits
|
|
36
|
+
- `maxFlushChunkBytes`: Maximum bytes per flush chunk (default: 8MB)
|
|
37
|
+
|
|
38
|
+
### ๐ง Changed
|
|
39
|
+
- **API Simplification**: Removed confirmation requirements from `deleteDatabase()` and `removeDatabase()`
|
|
40
|
+
- Methods now work directly without `force` or `confirm` options
|
|
41
|
+
- Names are self-explanatory and follow industry standards
|
|
42
|
+
- **Constructor Defaults**: Updated default options for better performance
|
|
43
|
+
- `batchSize`: Reduced from 100 to 50 for faster response
|
|
44
|
+
- `autoSave`: Enabled by default (true)
|
|
45
|
+
- `autoSaveThreshold`: 50 records
|
|
46
|
+
- `autoSaveInterval`: 5000ms (5 seconds)
|
|
47
|
+
- `forceSaveOnClose`: Enabled by default (true)
|
|
48
|
+
- **Method Behavior**:
|
|
49
|
+
- `destroy()`: Now equivalent to `close()` (closes instance, keeps file)
|
|
50
|
+
- `deleteDatabase()`: Permanently deletes database file
|
|
51
|
+
- `removeDatabase()`: Alias for `deleteDatabase()`
|
|
52
|
+
|
|
53
|
+
### ๐ Fixed
|
|
54
|
+
- **Query Operators**: Fixed issues with `$gt`, `$gte`, `$lt`, `$lte`, `$ne`, `$nin` operators
|
|
55
|
+
- **Data Duplication**: Resolved duplicate results in `find()` operations
|
|
56
|
+
- **Type Preservation**: Fixed numeric values being stored as strings in persistent indexes
|
|
57
|
+
- **Persistence Issues**: Corrected data persistence between database instances
|
|
58
|
+
- **Performance Test Logic**: Fixed test expectations for large dataset operations
|
|
59
|
+
|
|
60
|
+
### ๐ Documentation
|
|
61
|
+
- **Updated README.md**: Added comprehensive auto-save documentation and examples
|
|
62
|
+
- **Updated API.md**: Added new methods, events, and configuration options
|
|
63
|
+
- **New Examples**: Created `auto-save-example.js` and `close-vs-delete-example.js`
|
|
64
|
+
- **Enhanced Tests**: Added comprehensive test suite for auto-save functionality
|
|
65
|
+
|
|
66
|
+
### ๐งช Testing
|
|
67
|
+
- **New Test Suite**: Added `tests/auto-save.test.js` with 10 comprehensive tests
|
|
68
|
+
- **All Tests Passing**: 86 tests passing (100% success rate)
|
|
69
|
+
- **Improved Coverage**: Better test coverage for new auto-save features
|
|
70
|
+
|
|
71
|
+
## [2.0.2] - 2024-12-18
|
|
72
|
+
|
|
73
|
+
### ๐ Added
|
|
74
|
+
- **Persistent Indexes**: Indexes are now saved to disk and loaded on startup
|
|
75
|
+
- **Point Reading**: Efficient memory usage - only reads necessary data
|
|
76
|
+
- **Rich Query API**: Support for complex queries with operators, sorting, and pagination
|
|
77
|
+
- **Event-Driven Architecture**: Real-time notifications for all database operations
|
|
78
|
+
- **Automatic Integrity Validation**: Built-in data integrity checking and repair
|
|
79
|
+
- **Legacy Compatibility**: Automatic migration from JexiDB 1.x databases
|
|
80
|
+
- **Pure JavaScript**: No native dependencies, works everywhere
|
|
81
|
+
|
|
82
|
+
### ๐ง Changed
|
|
83
|
+
- **Performance**: 10-100x faster than JexiDB 1.x
|
|
84
|
+
- **Memory Usage**: 25% less memory consumption
|
|
85
|
+
- **File Format**: Improved JSONL architecture with separate index files
|
|
86
|
+
- **API**: Enhanced query methods with MongoDB-style operators
|
|
87
|
+
|
|
88
|
+
### ๐ Fixed
|
|
89
|
+
- **Data Integrity**: Safe truncation and consistent offsets
|
|
90
|
+
- **Test Isolation**: Proper test isolation and cleanup
|
|
91
|
+
- **V8 Dependency**: Removed dependency on V8 engine
|
|
92
|
+
|
|
93
|
+
## [2.0.1] - 2024-12-17
|
|
94
|
+
|
|
95
|
+
### ๐ Added
|
|
96
|
+
- **Initial Release**: First stable version of JexiDB 2.0
|
|
97
|
+
- **JSONL Architecture**: Pure JavaScript JSONL database implementation
|
|
98
|
+
- **Basic CRUD Operations**: Insert, find, update, delete operations
|
|
99
|
+
- **Index Support**: Basic indexing for fast queries
|
|
100
|
+
- **File Management**: Database file creation and management
|
|
101
|
+
|
|
102
|
+
### ๐ง Changed
|
|
103
|
+
- **Complete Rewrite**: New architecture from ground up
|
|
104
|
+
- **Performance Focus**: Optimized for speed and efficiency
|
|
105
|
+
- **Modern JavaScript**: ES6+ features and async/await support
|
|
106
|
+
|
|
107
|
+
### ๐ Fixed
|
|
108
|
+
- **Stability**: Improved error handling and edge cases
|
|
109
|
+
- **Compatibility**: Better Node.js version support
|
package/README.md
CHANGED
|
@@ -8,8 +8,10 @@
|
|
|
8
8
|
- **Persistent Indexes**: Fast searches with disk-persisted indexes that don't need rebuilding
|
|
9
9
|
- **Point Reading**: Efficient memory usage - only reads necessary data
|
|
10
10
|
- **Rich Query API**: Support for complex queries with operators, sorting, and pagination
|
|
11
|
+
- **Intelligent Auto-Save**: Automatic data persistence with configurable thresholds and intervals
|
|
12
|
+
- **Event-Driven Monitoring**: Real-time notifications for all database operations
|
|
13
|
+
- **Performance Optimization**: Adaptive batch sizes and memory management
|
|
11
14
|
- **Automatic Integrity Validation**: Built-in data integrity checking and repair
|
|
12
|
-
- **Event System**: Real-time notifications for database operations
|
|
13
15
|
- **Legacy Compatibility**: Automatic migration from JexiDB 1.x databases
|
|
14
16
|
- **Pure JavaScript**: No native dependencies, works everywhere, easy to deploy
|
|
15
17
|
|
|
@@ -54,7 +56,7 @@ const results = await db.query({ name: 'john doe' }, { caseInsensitive: true });
|
|
|
54
56
|
await db.update({ id: 1 }, { age: 31 });
|
|
55
57
|
await db.delete({ id: 1 });
|
|
56
58
|
await db.save();
|
|
57
|
-
await db.destroy()
|
|
59
|
+
await db.close(); // or await db.destroy()
|
|
58
60
|
```
|
|
59
61
|
|
|
60
62
|
### CommonJS
|
|
@@ -71,7 +73,7 @@ const db = new Database('./users.jdb', {
|
|
|
71
73
|
await db.init();
|
|
72
74
|
await db.insert({ id: 1, name: 'John' });
|
|
73
75
|
console.log(await db.findOne({ id: 1 }));
|
|
74
|
-
await db.destroy()
|
|
76
|
+
await db.close(); // or await db.destroy()
|
|
75
77
|
})();
|
|
76
78
|
```
|
|
77
79
|
|
|
@@ -90,13 +92,73 @@ const db = new Database(filePath, options);
|
|
|
90
92
|
**Options:**
|
|
91
93
|
```javascript
|
|
92
94
|
{
|
|
95
|
+
// Core options
|
|
93
96
|
indexes: {}, // Indexes for fields
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
+
create: true, // Create database if it doesn't exist
|
|
98
|
+
clear: false, // Clear database on load
|
|
99
|
+
|
|
100
|
+
// Auto-save configuration
|
|
101
|
+
autoSave: true, // Enable intelligent auto-save (default: true)
|
|
102
|
+
autoSaveThreshold: 50, // Flush buffer when it reaches this many records
|
|
103
|
+
autoSaveInterval: 5000, // Flush buffer every N milliseconds
|
|
104
|
+
forceSaveOnClose: true, // Always save when closing database
|
|
105
|
+
|
|
106
|
+
// Performance configuration
|
|
107
|
+
batchSize: 50, // Batch size for inserts (reduced for faster response)
|
|
108
|
+
adaptiveBatchSize: true, // Adjust batch size based on usage
|
|
109
|
+
minBatchSize: 10, // Minimum batch size for flush
|
|
110
|
+
maxBatchSize: 200 // Maximum batch size for performance
|
|
97
111
|
}
|
|
98
112
|
```
|
|
99
113
|
|
|
114
|
+
### Auto-Save Intelligence
|
|
115
|
+
|
|
116
|
+
JexiDB features intelligent auto-save capabilities that automatically manage data persistence without manual intervention.
|
|
117
|
+
|
|
118
|
+
#### Auto-Save Modes
|
|
119
|
+
|
|
120
|
+
**Intelligent Auto-Save (Default):**
|
|
121
|
+
- Automatically flushes buffer when it reaches the threshold (default: 50 records)
|
|
122
|
+
- Automatically flushes buffer every N milliseconds (default: 5000ms)
|
|
123
|
+
- Always saves when closing the database
|
|
124
|
+
- Provides real-time feedback through events
|
|
125
|
+
|
|
126
|
+
**Manual Mode:**
|
|
127
|
+
- Disable auto-save with `autoSave: false`
|
|
128
|
+
- Manually call `flush()` and `save()` when needed
|
|
129
|
+
- Useful for applications requiring precise control over persistence timing
|
|
130
|
+
|
|
131
|
+
#### Event-Driven Monitoring
|
|
132
|
+
|
|
133
|
+
```javascript
|
|
134
|
+
// Monitor auto-save operations
|
|
135
|
+
db.on('buffer-flush', (count) => {
|
|
136
|
+
console.log(`Flushed ${count} records`);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
db.on('buffer-full', () => {
|
|
140
|
+
console.log('Buffer reached threshold');
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
db.on('auto-save-timer', () => {
|
|
144
|
+
console.log('Time-based auto-save triggered');
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
db.on('save-complete', () => {
|
|
148
|
+
console.log('Database saved successfully');
|
|
149
|
+
});
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
#### Buffer Status Monitoring
|
|
153
|
+
|
|
154
|
+
```javascript
|
|
155
|
+
// Check buffer status anytime
|
|
156
|
+
const status = db.getBufferStatus();
|
|
157
|
+
console.log(`Pending: ${status.pendingCount}/${status.bufferSize}`);
|
|
158
|
+
console.log(`Should flush: ${status.shouldFlush}`);
|
|
159
|
+
console.log(`Auto-save enabled: ${status.autoSaveEnabled}`);
|
|
160
|
+
```
|
|
161
|
+
|
|
100
162
|
### Main Methods
|
|
101
163
|
|
|
102
164
|
#### `init()`
|
|
@@ -173,8 +235,46 @@ Counts records.
|
|
|
173
235
|
#### `save()`
|
|
174
236
|
Saves pending changes.
|
|
175
237
|
|
|
238
|
+
#### `flush()`
|
|
239
|
+
Flushes the insertion buffer to disk immediately.
|
|
240
|
+
|
|
241
|
+
#### `forceSave()`
|
|
242
|
+
Forces a save operation regardless of buffer size.
|
|
243
|
+
|
|
244
|
+
#### `getBufferStatus()`
|
|
245
|
+
Gets information about the current buffer state.
|
|
246
|
+
|
|
247
|
+
#### `configurePerformance(settings)`
|
|
248
|
+
Dynamically configures performance settings.
|
|
249
|
+
|
|
250
|
+
#### `getPerformanceConfig()`
|
|
251
|
+
Gets current performance configuration.
|
|
252
|
+
|
|
253
|
+
#### `close()`
|
|
254
|
+
Closes the database instance and saves pending changes.
|
|
255
|
+
|
|
176
256
|
#### `destroy()`
|
|
177
|
-
|
|
257
|
+
Closes the database instance and saves pending changes (equivalent to close()).
|
|
258
|
+
|
|
259
|
+
```javascript
|
|
260
|
+
await db.destroy() // Same as: await db.close()
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
#### `deleteDatabase()`
|
|
264
|
+
**โ ๏ธ WARNING: This permanently deletes the database file!**
|
|
265
|
+
|
|
266
|
+
Deletes the database file from disk and closes the instance.
|
|
267
|
+
|
|
268
|
+
```javascript
|
|
269
|
+
await db.deleteDatabase() // Deletes the database file permanently
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
#### `removeDatabase()`
|
|
273
|
+
Removes the database file from disk (alias for deleteDatabase).
|
|
274
|
+
|
|
275
|
+
```javascript
|
|
276
|
+
await db.removeDatabase() // Same as: await db.deleteDatabase()
|
|
277
|
+
```
|
|
178
278
|
|
|
179
279
|
#### `validateIntegrity(options)`
|
|
180
280
|
Validates database integrity.
|
|
@@ -216,13 +316,25 @@ Index statistics.
|
|
|
216
316
|
### Events
|
|
217
317
|
|
|
218
318
|
```javascript
|
|
319
|
+
// Core events
|
|
219
320
|
db.on('init', () => console.log('Database initialized'));
|
|
220
321
|
db.on('insert', (record, index) => console.log('Record inserted'));
|
|
221
322
|
db.on('update', (record, index) => console.log('Record updated'));
|
|
222
323
|
db.on('delete', (record, index) => console.log('Record deleted'));
|
|
223
324
|
db.on('before-save', () => console.log('Before save'));
|
|
224
325
|
db.on('save', () => console.log('Save completed'));
|
|
326
|
+
db.on('close', () => console.log('Database closed'));
|
|
225
327
|
db.on('destroy', () => console.log('Database destroyed'));
|
|
328
|
+
db.on('delete-database', () => console.log('Database file deleted'));
|
|
329
|
+
|
|
330
|
+
// Auto-save events
|
|
331
|
+
db.on('buffer-flush', (count) => console.log(`Buffer flushed: ${count} records`));
|
|
332
|
+
db.on('buffer-full', () => console.log('Buffer reached threshold'));
|
|
333
|
+
db.on('auto-save-timer', () => console.log('Time-based auto-save triggered'));
|
|
334
|
+
db.on('save-complete', () => console.log('Save operation completed'));
|
|
335
|
+
db.on('close-save-complete', () => console.log('Database closed with final save'));
|
|
336
|
+
db.on('close', () => console.log('Database closed'));
|
|
337
|
+
db.on('performance-configured', (config) => console.log('Performance reconfigured'));
|
|
226
338
|
```
|
|
227
339
|
|
|
228
340
|
## ๐ File Structure
|