const sqlite3 = require('sqlite3').verbose();
const db = new sqlite3.Database('mydatabase.db');
function queryDatabase(query) {
return new Promise((resolve, reject) => {
db.get(query, (err, row) => {
if (err) {
reject(err);
} else {
resolve(row);
}
});
});
}
async function main() {
try {
const result = await queryDatabase('SELECT value FROM mytable WHERE id = 1');
console.log(result.value);
} catch (err) {
console.error(err);
} finally {
db.close();
}
}
const sqlite3 = require('sqlite3').verbose(); const db = new sqlite3.Database('mydatabase.db');
function queryDatabase(query) { return new Promise((resolve, reject) => { db.get(query, (err, row) => { if (err) { reject(err); } else { resolve(row); } }); }); }
async function main() { try { const result = await queryDatabase('SELECT value FROM mytable WHERE id = 1'); console.log(result.value); } catch (err) { console.error(err); } finally { db.close(); } }
main();