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 all provider nodes
    const result = db.exec("SELECT id, provider, name, data FROM providerNodes");
    if (result[0]?.values) {
        console.log('All Provider Nodes:\n');
        result[0].values.forEach(row => {
            const data = JSON.parse(row[3] || '{}');
            console.log(`ID: ${row[0]}`);
            console.log(`Provider: ${row[1]}`);
            console.log(`Name: ${row[2]}`);
            console.log(`Prefix: ${data.prefix}`);
            console.log(`Base URL: ${data.baseUrl}`);
            console.log(`Has API Key: ${!!data.apiKey}`);
            console.log('---');
        });
    }
    
    db.close();
    process.exit(0);
});
