Download src/database/jdbc.js from vanducdev/botzalo: direct link, hf CLI and curl.
- Browser
- Download file 988 Bytes
-
https://huggingface.co/spaces/vanducdev/botzalo/resolve/main/src/database/jdbc.js
- Command line
-
hf download hf://spaces/vanducdev/botzalo/src/database/jdbc.js
-
curl -L -o jdbc.js https://huggingface.co/spaces/vanducdev/botzalo/resolve/main/src/database/jdbc.js
988 Bytes
| import { connection, NAME_TABLE_PLAYERS } from './index.js'; | |
| import Big from 'big.js'; | |
| export async function getTopPlayers() { | |
| try { | |
| // Lấy tất cả người chơi | |
| const [rows] = await connection.execute( | |
| `SELECT idUserZalo, playerName, balance FROM ${NAME_TABLE_PLAYERS}` | |
| ); | |
| // Chuyển đổi balance sang Big và sắp xếp lại | |
| const sortedPlayers = rows | |
| .map(player => ({ | |
| idUser: player.idUserZalo, | |
| playerName: player.playerName, | |
| balance: new Big(player.balance) | |
| })) | |
| .sort((a, b) => b.balance.minus(a.balance)) | |
| .slice(0, 20) // Lấy top 20 | |
| .map((player, index) => ({ | |
| rank: index + 1, | |
| idUser: player.idUser, | |
| playerName: player.playerName, | |
| balance: player.balance.toString() | |
| })); | |
| return sortedPlayers; | |
| } catch (error) { | |
| console.error('Lỗi khi lấy danh sách top người chơi:', error); | |
| return []; | |
| } | |
| } | |