Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
31 lines (24 loc) · 1.14 KB

File metadata and controls

31 lines (24 loc) · 1.14 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const { open } = require('./node/lib/index');
const db = open({ name: 'test_trans.sqlite', location: './' });
// Create table
db.executeSync('CREATE TABLE IF NOT EXISTS test_users (id INTEGER PRIMARY KEY, name TEXT, age INTEGER)');
// Insert initial data
db.executeSync('INSERT INTO test_users (name, age) VALUES (?, ?)', ['Alice', 30]);
db.executeSync('INSERT INTO test_users (name, age) VALUES (?, ?)', ['Bob', 25]);
db.executeSync('INSERT INTO test_users (name, age) VALUES (?, ?)', ['Charlie', 35]);
console.log('Before transaction:');
let result = db.executeSync('SELECT COUNT(*) as count FROM test_users');
console.log('Rows:', result.rows);
console.log('Count:', result.rows[0].count);
// Run transaction
(async () => {
await db.transaction(async (tx) => {
await tx.execute('INSERT INTO test_users (name, age) VALUES (?, ?)', ['David', 40]);
await tx.execute('INSERT INTO test_users (name, age) VALUES (?, ?)', ['Emma', 28]);
});
console.log('\nAfter transaction:');
result = db.executeSync('SELECT COUNT(*) as count FROM test_users');
console.log('Rows:', result.rows);
console.log('Count:', result.rows[0].count);
db.close();
})();
Morty Proxy This is a proxified and sanitized view of the page, visit original site.