File size: 885 Bytes
2c0a8a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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);
}