Files
MetonaSqlark/tests/zz-dbg.test.ts
T

25 lines
1.0 KiB
TypeScript

import { AriaEngine } from '../src/engine/aria/index';
import { createSchema } from '../src/table/schema';
it('dbg: call fk directly', async () => {
const engine = new AriaEngine({ storageBackend: 'memory' } as never);
await engine.open('dbg-fk2', 1);
await engine.createTable(createSchema('parent', {
id: { type: 'string', primaryKey: true },
}));
await engine.createTable(createSchema('child', {
id: { type: 'string', primaryKey: true },
pid: { type: 'string', references: 'parent:id', onDelete: 'CASCADE' },
}));
await engine.insert('parent', [{ id: 'p1' }]);
await engine.insert('child', [{ id: 'c1', pid: 'p1' }]);
const wal: unknown[] = [];
const n = await (engine as any).applyForeignKeyRules('parent', 'p1', wal, new Set<string>());
console.log('fk direct result:', n, 'wal records:', wal.length);
console.log('child count after fk:', await engine.count('child'));
// 手动 CASCADE 验证
const c = await (engine as any).lsm.get('child:c1');
console.log('child:c1 in lsm:', c ? 'YES' : 'NO');
await engine.close();
});