jexidb 2.0.1 → 2.0.2

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/README.md CHANGED
@@ -21,22 +21,18 @@ npm install jexidb
21
21
 
22
22
  ## 🚀 Quick Start
23
23
 
24
+ ### ESM
25
+
24
26
  ```javascript
25
- // import { Database } from 'jexidb'
26
- const { Database } = require('jexidb');
27
+ import Database from 'jexidb';
27
28
 
28
- // Create database with indexes (supports both .jdb and .jsonl)
29
+ // Prefer default import aliased as Database for clarity
29
30
  const db = new Database('./users.jdb', {
30
- indexes: {
31
- id: 'number',
32
- email: 'string',
33
- age: 'number'
34
- },
31
+ indexes: { id: 'number', email: 'string', age: 'number' },
35
32
  autoSave: true,
36
33
  validateOnInit: true
37
34
  });
38
35
 
39
- // Initialize
40
36
  await db.init();
41
37
 
42
38
  // Event listeners
@@ -45,12 +41,7 @@ db.on('update', (record, index) => console.log(`Record updated at index ${index}
45
41
  db.on('save', () => console.log('Changes saved'));
46
42
 
47
43
  // Insert data
48
- const user = await db.insert({
49
- id: 1,
50
- name: 'John Doe',
51
- email: 'john@example.com',
52
- age: 30
53
- });
44
+ await db.insert({ id: 1, name: 'John Doe', email: 'john@example.com', age: 30 });
54
45
 
55
46
  // Search data (both methods work)
56
47
  const john = await db.findOne({ id: 1 });
@@ -59,19 +50,31 @@ const youngUsers = await db.find({ age: { '<': 30 } });
59
50
  // JexiDB 1.x compatible query
60
51
  const results = await db.query({ name: 'john doe' }, { caseInsensitive: true });
61
52
 
62
- // Update data
53
+ // Update / Delete / Save
63
54
  await db.update({ id: 1 }, { age: 31 });
64
-
65
- // Remove data
66
55
  await db.delete({ id: 1 });
67
-
68
- // Save changes
69
56
  await db.save();
70
-
71
- // Destroy database
72
57
  await db.destroy();
73
58
  ```
74
59
 
60
+ ### CommonJS
61
+
62
+ ```javascript
63
+ const Database = require('jexidb');
64
+ // Alternatively (backward compatible): const { Database } = require('jexidb');
65
+
66
+ const db = new Database('./users.jdb', {
67
+ indexes: { id: 'number', email: 'string', age: 'number' }
68
+ });
69
+
70
+ (async () => {
71
+ await db.init();
72
+ await db.insert({ id: 1, name: 'John' });
73
+ console.log(await db.findOne({ id: 1 }));
74
+ await db.destroy();
75
+ })();
76
+ ```
77
+
75
78
  ## 📚 API Reference
76
79
 
77
80
  ### Constructor
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.Database = void 0;
6
7
  Object.defineProperty(exports, "FileHandler", {
7
8
  enumerable: true,
8
9
  get: function () {
@@ -207,11 +208,15 @@ class JexiDBCompatibility extends _JSONLDatabase.default {
207
208
  }
208
209
 
209
210
  /**
210
- * Compatibility method: walk() -> find() with async iteration
211
+ * Streaming iterator over records without loading all into memory
212
+ * Supports a limited subset of options: { limit }
211
213
  */
212
214
  async *walk(options = {}) {
213
- const results = await this.find({}, options);
214
- for (const record of results) {
215
+ // Delegate to core engine streaming implementation
216
+ // Ensure pending inserts are flushed by calling super.walk
217
+ for await (const record of super.walk({
218
+ limit: options.limit
219
+ })) {
215
220
  yield record;
216
221
  }
217
222
  }
@@ -289,7 +294,11 @@ class JexiDBCompatibility extends _JSONLDatabase.default {
289
294
  */
290
295
 
291
296
  // Export the compatibility wrapper as default
292
- var _default = exports.default = JexiDBCompatibility; // Export auxiliary classes for advanced use
297
+ var _default = exports.default = JexiDBCompatibility; // Retrocompat: named export 'Database' (JexiDB v1 used { Database })
298
+ const Database = exports.Database = JexiDBCompatibility;
299
+
300
+ // Export auxiliary classes for advanced use
301
+
293
302
  // Export useful constants
294
303
  const OPERATORS = exports.OPERATORS = {
295
304
  GT: '>',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jexidb",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "JexiDB - A fast and reliable local CRUD database for Electron apps with pure JavaScript JSONL architecture",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./src/index.js",
package/src/index.js CHANGED
@@ -183,11 +183,13 @@ class JexiDBCompatibility extends JSONLDatabase {
183
183
  }
184
184
 
185
185
  /**
186
- * Compatibility method: walk() -> find() with async iteration
186
+ * Streaming iterator over records without loading all into memory
187
+ * Supports a limited subset of options: { limit }
187
188
  */
188
189
  async *walk(options = {}) {
189
- const results = await this.find({}, options);
190
- for (const record of results) {
190
+ // Delegate to core engine streaming implementation
191
+ // Ensure pending inserts are flushed by calling super.walk
192
+ for await (const record of super.walk({ limit: options.limit })) {
191
193
  yield record;
192
194
  }
193
195
  }
@@ -266,6 +268,8 @@ class JexiDBCompatibility extends JSONLDatabase {
266
268
 
267
269
  // Export the compatibility wrapper as default
268
270
  export default JexiDBCompatibility;
271
+ // Retrocompat: named export 'Database' (JexiDB v1 used { Database })
272
+ export const Database = JexiDBCompatibility;
269
273
 
270
274
  // Export auxiliary classes for advanced use
271
275
  export { FileHandler, IndexManager, IntegrityChecker };