New test for sqlite sessions
This commit is contained in:
parent
1c9af289cd
commit
ecbe2863fa
4 changed files with 137 additions and 0 deletions
34
Smoke/nodejs-sqlite/sqlite-sessions.js
Normal file
34
Smoke/nodejs-sqlite/sqlite-sessions.js
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
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();
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue