The original test/parallel/test-sqlite.js test appears to time out in the CI occasionally. This commit splits the test into several smaller test files. Fixes: https://github.com/nodejs/node/issues/54006 PR-URL: https://github.com/nodejs/node/pull/54014 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
68 lines
1.8 KiB
JavaScript
68 lines
1.8 KiB
JavaScript
// Flags: --experimental-sqlite
|
|
'use strict';
|
|
require('../common');
|
|
const tmpdir = require('../common/tmpdir');
|
|
const { join } = require('node:path');
|
|
const { DatabaseSync } = require('node:sqlite');
|
|
const { suite, test } = require('node:test');
|
|
let cnt = 0;
|
|
|
|
tmpdir.refresh();
|
|
|
|
function nextDb() {
|
|
return join(tmpdir.path, `database-${cnt++}.db`);
|
|
}
|
|
|
|
suite('manual transactions', () => {
|
|
test('a transaction is committed', (t) => {
|
|
const db = new DatabaseSync(nextDb());
|
|
t.after(() => { db.close(); });
|
|
const setup = db.exec(`
|
|
CREATE TABLE data(
|
|
key INTEGER PRIMARY KEY
|
|
) STRICT;
|
|
`);
|
|
t.assert.strictEqual(setup, undefined);
|
|
t.assert.deepStrictEqual(
|
|
db.prepare('BEGIN').run(),
|
|
{ changes: 0, lastInsertRowid: 0 },
|
|
);
|
|
t.assert.deepStrictEqual(
|
|
db.prepare('INSERT INTO data (key) VALUES (100)').run(),
|
|
{ changes: 1, lastInsertRowid: 100 },
|
|
);
|
|
t.assert.deepStrictEqual(
|
|
db.prepare('COMMIT').run(),
|
|
{ changes: 1, lastInsertRowid: 100 },
|
|
);
|
|
t.assert.deepStrictEqual(
|
|
db.prepare('SELECT * FROM data').all(),
|
|
[{ key: 100 }],
|
|
);
|
|
});
|
|
|
|
test('a transaction is rolled back', (t) => {
|
|
const db = new DatabaseSync(nextDb());
|
|
t.after(() => { db.close(); });
|
|
const setup = db.exec(`
|
|
CREATE TABLE data(
|
|
key INTEGER PRIMARY KEY
|
|
) STRICT;
|
|
`);
|
|
t.assert.strictEqual(setup, undefined);
|
|
t.assert.deepStrictEqual(
|
|
db.prepare('BEGIN').run(),
|
|
{ changes: 0, lastInsertRowid: 0 },
|
|
);
|
|
t.assert.deepStrictEqual(
|
|
db.prepare('INSERT INTO data (key) VALUES (100)').run(),
|
|
{ changes: 1, lastInsertRowid: 100 },
|
|
);
|
|
t.assert.deepStrictEqual(
|
|
db.prepare('ROLLBACK').run(),
|
|
{ changes: 1, lastInsertRowid: 100 },
|
|
);
|
|
t.assert.deepStrictEqual(db.prepare('SELECT * FROM data').all(), []);
|
|
});
|
|
});
|