bigbasealpha
Version:
Professional Grade Custom Database System - A sophisticated, dependency-free database with encryption, caching, indexing, and web dashboard
40 lines (36 loc) • 1.23 kB
JavaScript
// Test for all supported formats in BigBaseAlpha storage
const fs = require('fs');
const path = require('path');
const { StorageEngine } = require('../src/storage/index.js');
const TEST_COLLECTION = 'test';
const TEST_ID = 'format-test';
const TEST_DOC = {
id: TEST_ID,
name: 'Format Test',
value: 42,
arr: [1,2,3],
nested: { foo: 'bar', num: 7 }
};
const FORMATS = ['json', 'binary', 'hybrid', 'csv', 'xml', 'yaml', 'db'];
(async () => {
for (const format of FORMATS) {
const basePath = path.join(__dirname, 'format_test_' + format);
if (!fs.existsSync(basePath)) fs.mkdirSync(basePath);
const engine = new StorageEngine({ basePath, format });
await engine._initFormat();
// Write
await engine._writeFile(
path.join(basePath, `${TEST_ID}.${format}`),
await engine._serializeDocument(TEST_DOC)
);
// Read
const data = await engine._readFile(
path.join(basePath, `${TEST_ID}.${format}`)
);
const doc = await engine._deserializeDocument(data);
console.log(`[${format}]`, doc);
// Cleanup
fs.rmSync(basePath, { recursive: true, force: true });
}
console.log('All format tests completed!');
})();