const initSqlJs = require('sql.js');
const fs = require('fs');

initSqlJs().then(SQL => {
    const buffer = fs.readFileSync('E:/var/lib/9router/db/data.sqlite');
    const db = new SQL.Database(buffer);
    
    // Get schema
    const schema = db.exec("SELECT sql FROM sqlite_master WHERE name='providerNodes'");
    console.log('providerNodes schema:');
    console.log(schema[0]?.values[0][0]);
    
    // Get all nodes without provider column
    const result = db.exec("SELECT id, data FROM providerNodes");
    if (result[0]?.values) {
        console.log('\nAll Provider Nodes:\n');
        result[0].values.forEach(row => {
            const data = JSON.parse(row[1] || '{}');
            console.log(`ID: ${row[0]}`);
            console.log(`Prefix: ${data.prefix}`);
            console.log(`Base URL: ${data.baseUrl}`);
            console.log(`Name: ${data.name}`);
            console.log('---');
        });
    }
    
    db.close();
    process.exit(0);
});
