import { DatabaseSync } from 'node:sqlite'; const sourceDb = new DatabaseSync(':memory:'); const targetDb = new DatabaseSync(':memory:'); sourceDb.exec('CREATE TABLE data(key INTEGER PRIMARY KEY, value TEXT)'); targetDb.exec('CREATE TABLE data(key INTEGER PRIMARY KEY, value TEXT)'); const session = sourceDb.createSession(); try { const insert = sourceDb.prepare('INSERT INTO data (key, value) VALUES (?, ?)'); insert.run(1, 'hello'); insert.run(2, 'world'); const changeset = session.changeset(); targetDb.applyChangeset(changeset); const sourceData = sourceDb.prepare('SELECT * FROM data ORDER BY key').all(); const targetData = targetDb.prepare('SELECT * FROM data ORDER BY key').all(); console.log('Source Data:', sourceData); console.log('Target Data:', targetData); if (JSON.stringify(sourceData) === JSON.stringify(targetData)) { console.log('Test Passed: Changes were successfully applied to the target database'); } else { console.log('Test Failed: Data mismatch between source and target databases'); } } finally { session.close(); }