mpackdb
All repositories: gitoria
1.7 KB
import MPackDB, { PrimaryKeyType } from '../src/MPackDB.js';import { rm } from 'fs/promises';const TEST_DB_PATH = 'db/indexed';console.log('--- Indexed Database Test ---');// Clean upawait rm(TEST_DB_PATH, { recursive: true, force: true });// Create database WITH indexesconst db = new MPackDB(`${TEST_DB_PATH}/users`, {primaryKey: 'id',primaryKeyType: PrimaryKeyType.NUMBER,indexes: ['id', 'email', '*age'] // id and email are lexical, age is numeric (*)});console.log('\nTest 1: Insert with indexes');await db.insert({ name: 'Alice', email: '[email protected]', age: 30 });await db.insert({ name: 'Bob', email: '[email protected]', age: 25 });await db.insert({ name: 'Charlie', email: '[email protected]', age: 35 });console.log('✓ Inserted 3 records');console.log('\nTest 1.5: Persist indexes to disk');if (db._indexManager) {await db._indexManager.persist();console.log('✓ Indexes persisted');}console.log('\nTest 2: Read all (should use index)');const all = await db.find();console.log('✓ Found', all.length, 'records:', all);console.log('\nTest 3: Find by primary key (should use index)');const alice = await db.find(0);console.log('✓ Found by ID:', alice);console.log('\nTest 4: Delete (should update index)');await db.delete(r => r.age === 25);const remaining = await db.find();console.log('✓ Remaining:', remaining.length, 'records');console.log('\nTest 5: Verify index files created');const { readdirSync } = await import('fs');const files = readdirSync(TEST_DB_PATH);const indexFiles = files.filter(f => f.endsWith('.txt'));console.log('✓ Index files:', indexFiles);if (indexFiles.length !== 3) {throw new Error(`Expected 3 index files, got ${indexFiles.length}`);}console.log('\n✓ All indexed tests passed!');
Branches
- mastermain branch
Latest commits
- 87888725release 1.0.7caramboleyo
- c4cdb9b6node: import prefixes (Deno compat) + pre-existing index-state WIPcaramboleyo
- 0afb8f4bupdate now must be a callbackcaramboleyo
- cde73eb4release 1.0.6caramboleyo
- d01dda02add index hints, intersection, boundingBox; remove findByIndexcaramboleyo
- b8ffc1a0release 1.0.5caramboleyo
- d47876a1reimplemented lost features like indexed find and more testscaramboleyo
- 7f08da9afixed insert ignoring model definitioncaramboleyo
- 705774a9added flush before findcaramboleyo
- b4db6391initial commitcaramboleyo