mpackdb
All repositories: gitoria
1.6 KB
import MPackDB, { PrimaryKeyType } from '../src/MPackDB.js';import { rm } from 'fs/promises';import { statSync } from 'fs';const TEST_DB_PATH = 'db/autopersist';console.log('--- Auto-Persist Test ---\n');// Clean upawait rm(TEST_DB_PATH, { recursive: true, force: true });// Create DB with low threshold for testingconst db = new MPackDB(`${TEST_DB_PATH}/users`, {primaryKey: 'id',primaryKeyType: PrimaryKeyType.NUMBER,indexes: ['id', 'name'],indexPersistThreshold: 5, // Persist after 5 insertsindexPersistInterval: 0 // Disable periodic (only threshold-based)});console.log('1. Insert 3 records (below threshold)');await db.insert({ name: 'Alice', age: 30 });await db.insert({ name: 'Bob', age: 25 });await db.insert({ name: 'Charlie', age: 35 });// Check index fileslet idIndexSize = statSync(`${TEST_DB_PATH}/users.id.txt`).size;console.log(` Index file size: ${idIndexSize} bytes (should be 0 - not persisted yet)`);console.log('\n2. Insert 3 more records (crosses threshold of 5)');await db.insert({ name: 'Dave', age: 40 });await db.insert({ name: 'Eve', age: 28 });await db.insert({ name: 'Frank', age: 33 });// Wait a bit for async persistawait new Promise(resolve => setTimeout(resolve, 100));idIndexSize = statSync(`${TEST_DB_PATH}/users.id.txt`).size;console.log(` Index file size: ${idIndexSize} bytes (should be >0 - auto-persisted!)`);console.log('\n3. Test close() - should persist remaining deltas');await db.insert({ name: 'Grace', age: 29 });await db.close();idIndexSize = statSync(`${TEST_DB_PATH}/users.id.txt`).size;console.log(` Index file size: ${idIndexSize} bytes (should include all 7 records)`);console.log('\n✓ Auto-persist works!');
Branches
- mastermain branch
Latest commits
- 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