import Database from 'better-sqlite3'; import path from 'path'; import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); // Connexion à la DB partagée avec le Bot Python const DB_PATH = '/data/aviator_db.db'; let db; try { db = new Database(DB_PATH, { readonly: true }); console.log("✅ [API] Connecté à SQLite (Read-only mode)"); } catch (err) { console.error("❌ [API] Erreur de connexion DB:", err.message); process.exit(1); } // Récupérer les X derniers rounds export function getLastRounds(limit = 100) { return db.prepare('SELECT * FROM rounds ORDER BY id DESC LIMIT ?').all(limit); } // Récupérer TOUTES les cotes pour les calculs globaux export function getAllCotes() { const rows = db.prepare('SELECT cote FROM rounds').all(); return rows.map(r => r.cote); }