check-db.cjsā¢1.61 kB
#!/usr/bin/env node
const sqlite3 = require('sqlite3').verbose();
const path = require('path');
const dbPath = './data/egw-writings.db';
const db = new sqlite3.Database(dbPath);
console.log('š Checking database structure...');
db.all("SELECT name FROM sqlite_master WHERE type='table'", (err, tables) => {
if (err) {
console.error('ā Error:', err.message);
return;
}
console.log('š Tables found:');
tables.forEach(table => {
console.log(` - ${table.name}`);
});
// Check if books table exists and get sample data
if (tables.some(t => t.name === 'books')) {
console.log('\nš Sample books data:');
db.all("SELECT book_id, title, author FROM books LIMIT 3", (err, rows) => {
if (err) {
console.error('ā Error querying books:', err.message);
} else {
rows.forEach(row => {
console.log(` ${row.book_id}: ${row.title} by ${row.author}`);
});
}
// Check if paragraphs table exists
if (tables.some(t => t.name === 'paragraphs')) {
console.log('\nš Sample paragraphs data:');
db.all("SELECT COUNT(*) as count FROM paragraphs", (err, result) => {
if (err) {
console.error('ā Error counting paragraphs:', err.message);
} else {
console.log(` Total paragraphs: ${result[0].count}`);
}
db.close();
});
} else {
console.log('\nā No paragraphs table found');
db.close();
}
});
} else {
console.log('\nā No books table found');
db.close();
}
});