mirror of
https://github.com/mudabbir-ahmad/peworkshop.git
synced 2026-10-07 19:50:20 +00:00
16 lines
486 B
JavaScript
16 lines
486 B
JavaScript
const Database = require('better-sqlite3');
|
|
|
|
// Use an in-memory database for testing
|
|
const db = new Database(':memory:');
|
|
|
|
// Create a table
|
|
db.exec('CREATE TABLE test (id INTEGER PRIMARY KEY, name TEXT)');
|
|
|
|
// Insert data
|
|
const insert = db.prepare('INSERT INTO test (name) VALUES (?)');
|
|
insert.run('Alice');
|
|
insert.run('Bob');
|
|
|
|
// Query data
|
|
const rows = db.prepare('SELECT * FROM test').all();
|
|
console.log(rows); // Should output: [ { id: 1, name: 'Alice' }, { id: 2, name: 'Bob' } ]
|