jexidb 2.0.3 โ 2.1.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/.babelrc +13 -0
- package/.gitattributes +2 -0
- package/CHANGELOG.md +132 -101
- package/LICENSE +21 -21
- package/README.md +301 -639
- package/babel.config.json +5 -0
- package/dist/Database.cjs +3896 -0
- package/docs/API.md +1051 -390
- package/docs/EXAMPLES.md +701 -177
- package/docs/README.md +194 -184
- package/examples/iterate-usage-example.js +157 -0
- package/examples/simple-iterate-example.js +115 -0
- package/jest.config.js +24 -0
- package/package.json +63 -54
- package/scripts/README.md +47 -0
- package/scripts/clean-test-files.js +75 -0
- package/scripts/prepare.js +31 -0
- package/scripts/run-tests.js +80 -0
- package/src/Database.mjs +4130 -0
- package/src/FileHandler.mjs +1101 -0
- package/src/OperationQueue.mjs +279 -0
- package/src/SchemaManager.mjs +268 -0
- package/src/Serializer.mjs +511 -0
- package/src/managers/ConcurrencyManager.mjs +257 -0
- package/src/managers/IndexManager.mjs +1403 -0
- package/src/managers/QueryManager.mjs +1273 -0
- package/src/managers/StatisticsManager.mjs +262 -0
- package/src/managers/StreamingProcessor.mjs +429 -0
- package/src/managers/TermManager.mjs +278 -0
- package/test/$not-operator-with-and.test.js +282 -0
- package/test/README.md +8 -0
- package/test/close-init-cycle.test.js +256 -0
- package/test/critical-bugs-fixes.test.js +1069 -0
- package/test/index-persistence.test.js +306 -0
- package/test/index-serialization.test.js +314 -0
- package/test/indexed-query-mode.test.js +360 -0
- package/test/iterate-method.test.js +272 -0
- package/test/query-operators.test.js +238 -0
- package/test/regex-array-fields.test.js +129 -0
- package/test/score-method.test.js +238 -0
- package/test/setup.js +17 -0
- package/test/term-mapping-minimal.test.js +154 -0
- package/test/term-mapping-simple.test.js +257 -0
- package/test/term-mapping.test.js +514 -0
- package/test/writebuffer-flush-resilience.test.js +204 -0
- package/dist/FileHandler.js +0 -688
- package/dist/IndexManager.js +0 -353
- package/dist/IntegrityChecker.js +0 -364
- package/dist/JSONLDatabase.js +0 -1333
- package/dist/index.js +0 -617
- package/docs/MIGRATION.md +0 -295
- package/examples/auto-save-example.js +0 -158
- package/examples/cjs-usage.cjs +0 -82
- package/examples/close-vs-delete-example.js +0 -71
- package/examples/esm-usage.js +0 -113
- package/examples/example-columns.idx.jdb +0 -0
- package/examples/example-columns.jdb +0 -9
- 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 +0 -5
- package/examples/simple-test.js +0 -55
- package/src/FileHandler.js +0 -674
- package/src/IndexManager.js +0 -363
- package/src/IntegrityChecker.js +0 -379
- package/src/JSONLDatabase.js +0 -1391
- package/src/index.js +0 -608
package/examples/esm-usage.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
// Example: Using JexiDB with ESM (ES Modules)
|
|
2
|
-
// This file demonstrates how to use the library in modern ESM environments
|
|
3
|
-
|
|
4
|
-
import Database from 'jexidb';
|
|
5
|
-
|
|
6
|
-
async function main() {
|
|
7
|
-
console.log('๐ JexiDB Examples\n');
|
|
8
|
-
|
|
9
|
-
// Example 1: Basic usage
|
|
10
|
-
console.log('=== Example 1: Basic Usage ===');
|
|
11
|
-
|
|
12
|
-
const db = new Database('./example-users.jdb', {
|
|
13
|
-
indexes: { id: 'number', email: 'string', age: 'number' }
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
await db.init();
|
|
17
|
-
|
|
18
|
-
// Insert records
|
|
19
|
-
await db.insert({ id: 1, name: 'John Doe', email: 'john@example.com', age: 30 });
|
|
20
|
-
await db.insert({ id: 2, name: 'Jane Smith', email: 'jane@example.com', age: 25 });
|
|
21
|
-
|
|
22
|
-
console.log('โ
Records inserted: John Doe, Jane Smith');
|
|
23
|
-
|
|
24
|
-
// Find all records
|
|
25
|
-
const allUsers = await db.find({});
|
|
26
|
-
console.log('๐ All users:', allUsers.length);
|
|
27
|
-
|
|
28
|
-
// Find with criteria
|
|
29
|
-
const youngUsers = await db.find({ age: { '<': 30 } });
|
|
30
|
-
console.log('๐ถ Young users:', youngUsers.length);
|
|
31
|
-
|
|
32
|
-
// Find one record
|
|
33
|
-
const john = await db.findOne({ name: 'John Doe' });
|
|
34
|
-
console.log('๐ค John user:', john?.name);
|
|
35
|
-
|
|
36
|
-
// Update records
|
|
37
|
-
const updated = await db.update({ id: 1 }, { age: 31 });
|
|
38
|
-
console.log('๐ Updated records:', updated?.length);
|
|
39
|
-
|
|
40
|
-
// Get statistics
|
|
41
|
-
const stats = await db.getStats();
|
|
42
|
-
console.log('๐ Database stats:', stats.summary);
|
|
43
|
-
|
|
44
|
-
await db.save();
|
|
45
|
-
console.log('๐พ Database saved');
|
|
46
|
-
|
|
47
|
-
await db.destroy();
|
|
48
|
-
console.log('๐ Database closed\n');
|
|
49
|
-
|
|
50
|
-
// Example 2: New options (create, clear)
|
|
51
|
-
console.log('=== Example 2: New Options (create, clear) ===');
|
|
52
|
-
|
|
53
|
-
const db2 = new Database('./example-options.jdb', {
|
|
54
|
-
indexes: { category: 'string' },
|
|
55
|
-
create: true,
|
|
56
|
-
clear: false
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
await db2.init();
|
|
60
|
-
console.log('โ
Database created with create: true');
|
|
61
|
-
|
|
62
|
-
await db2.insert({ id: 1, category: 'Electronics' });
|
|
63
|
-
await db2.insert({ id: 2, category: 'Books' });
|
|
64
|
-
await db2.save();
|
|
65
|
-
await db2.destroy();
|
|
66
|
-
|
|
67
|
-
// Test clear option
|
|
68
|
-
const db3 = new Database('./example-options.jdb', {
|
|
69
|
-
indexes: { category: 'string' },
|
|
70
|
-
clear: true
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
await db3.init();
|
|
74
|
-
console.log('โ
Database cleared with clear: true, length:', db3.length);
|
|
75
|
-
await db3.destroy();
|
|
76
|
-
|
|
77
|
-
// Example 3: readColumnIndex
|
|
78
|
-
console.log('\n=== Example 3: readColumnIndex ===');
|
|
79
|
-
|
|
80
|
-
const db4 = new Database('./example-columns.jdb', {
|
|
81
|
-
indexes: { category: 'string', status: 'string' },
|
|
82
|
-
create: true
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
await db4.init();
|
|
86
|
-
|
|
87
|
-
await db4.insertMany([
|
|
88
|
-
{ id: 1, category: 'Electronics', status: 'active' },
|
|
89
|
-
{ id: 2, category: 'Books', status: 'inactive' },
|
|
90
|
-
{ id: 3, category: 'Electronics', status: 'active' },
|
|
91
|
-
{ id: 4, category: 'Clothing', status: 'active' }
|
|
92
|
-
]);
|
|
93
|
-
|
|
94
|
-
// Get unique values from indexed columns
|
|
95
|
-
const categories = db4.readColumnIndex('category');
|
|
96
|
-
console.log('๐ Unique categories:', Array.from(categories));
|
|
97
|
-
|
|
98
|
-
const statuses = db4.readColumnIndex('status');
|
|
99
|
-
console.log('๐ Unique statuses:', Array.from(statuses));
|
|
100
|
-
|
|
101
|
-
// Test error for non-indexed column
|
|
102
|
-
try {
|
|
103
|
-
db4.readColumnIndex('name');
|
|
104
|
-
} catch (error) {
|
|
105
|
-
console.log('โ
Correctly threw error for non-indexed column:', error.message);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
await db4.destroy();
|
|
109
|
-
|
|
110
|
-
console.log('\n๐ All examples completed successfully!');
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
main().catch(console.error);
|
|
Binary file
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
{"id":1,"category":"Electronics","status":"active","_id":0,"_created":1754747670129,"_updated":1754747670129}
|
|
2
|
-
{"id":2,"category":"Books","status":"inactive","_id":1,"_created":1754747670129,"_updated":1754747670129}
|
|
3
|
-
{"id":3,"category":"Electronics","status":"active","_id":2,"_created":1754747670129,"_updated":1754747670129}
|
|
4
|
-
{"id":4,"category":"Clothing","status":"active","_id":3,"_created":1754747670129,"_updated":1754747670129}
|
|
5
|
-
{"id":1,"category":"Electronics","status":"active","_id":4,"_created":1754747697710,"_updated":1754747697710}
|
|
6
|
-
{"id":2,"category":"Books","status":"inactive","_id":5,"_created":1754747697710,"_updated":1754747697710}
|
|
7
|
-
{"id":3,"category":"Electronics","status":"active","_id":6,"_created":1754747697710,"_updated":1754747697710}
|
|
8
|
-
{"id":4,"category":"Clothing","status":"active","_id":7,"_created":1754747697710,"_updated":1754747697710}
|
|
9
|
-
[0,110,216,326,433,543,649,759]
|
|
Binary file
|
|
File without changes
|
|
Binary file
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
{"id":1,"name":"John Doe","email":"john@example.com","age":31,"_id":0,"_created":1754747670096,"_updated":1754747670100}
|
|
2
|
-
{"id":2,"name":"Jane Smith","email":"jane@example.com","age":25,"_id":1,"_created":1754747670096,"_updated":1754747670096}
|
|
3
|
-
{"id":1,"name":"John Doe","email":"john@example.com","age":31,"_id":2,"_created":1754747697684,"_updated":1754747697691}
|
|
4
|
-
{"id":2,"name":"Jane Smith","email":"jane@example.com","age":25,"_id":3,"_created":1754747697684,"_updated":1754747697684}
|
|
5
|
-
[0,121,244,365]
|
package/examples/simple-test.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
// Simple test to demonstrate readColumnIndex method
|
|
2
|
-
const Database = require('../dist/index.js').default;
|
|
3
|
-
|
|
4
|
-
async function testReadColumnIndex() {
|
|
5
|
-
console.log('๐งช Testing readColumnIndex Method\n');
|
|
6
|
-
|
|
7
|
-
const db = new Database('./test-columns.jdb', {
|
|
8
|
-
indexes: { category: 'string', status: 'string' },
|
|
9
|
-
create: true
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
await db.init();
|
|
13
|
-
|
|
14
|
-
// Insert test data with duplicates
|
|
15
|
-
await db.insertMany([
|
|
16
|
-
{ id: 1, category: 'Electronics', status: 'active', price: 100 },
|
|
17
|
-
{ id: 2, category: 'Books', status: 'inactive', price: 20 },
|
|
18
|
-
{ id: 3, category: 'Electronics', status: 'active', price: 150 }, // Duplicate category and status
|
|
19
|
-
{ id: 4, category: 'Clothing', status: 'active', price: 50 },
|
|
20
|
-
{ id: 5, category: 'Electronics', status: 'active', price: 200 } // Another duplicate
|
|
21
|
-
]);
|
|
22
|
-
await db.save();
|
|
23
|
-
|
|
24
|
-
console.log('๐ Test Data Inserted:');
|
|
25
|
-
console.log(' - 5 records total');
|
|
26
|
-
console.log(' - 3 Electronics, 1 Books, 1 Clothing');
|
|
27
|
-
console.log(' - 4 active, 1 inactive status');
|
|
28
|
-
console.log(' - 5 different prices\n');
|
|
29
|
-
|
|
30
|
-
// Test indexed columns
|
|
31
|
-
console.log('=== Indexed Columns ===');
|
|
32
|
-
|
|
33
|
-
const categories = db.readColumnIndex('category');
|
|
34
|
-
console.log('๐ readColumnIndex("category"):', Array.from(categories));
|
|
35
|
-
// Expected: ['Electronics', 'Books', 'Clothing']
|
|
36
|
-
|
|
37
|
-
const statuses = db.readColumnIndex('status');
|
|
38
|
-
console.log('๐ readColumnIndex("status"):', Array.from(statuses));
|
|
39
|
-
// Expected: ['active', 'inactive']
|
|
40
|
-
|
|
41
|
-
// Test non-indexed columns (should throw error)
|
|
42
|
-
console.log('\n=== Non-Indexed Columns ===');
|
|
43
|
-
|
|
44
|
-
try {
|
|
45
|
-
const prices = db.readColumnIndex('price');
|
|
46
|
-
console.log('โ This should not appear');
|
|
47
|
-
} catch (error) {
|
|
48
|
-
console.log('โ readColumnIndex("price") error:', error.message);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
await db.destroy();
|
|
52
|
-
console.log('\nโ
Test completed successfully!');
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
testReadColumnIndex().catch(console.error);
|