Ajout panel + récup infos depuis SQL + fix noms de fichiers
This commit is contained in:
23
utils/getRewardData.js
Normal file
23
utils/getRewardData.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const mysql = require('mysql2/promise')
|
||||
|
||||
module.exports = async function () {
|
||||
// Create a connection to the MySQL database
|
||||
const connection = await mysql.createConnection({
|
||||
host: process.env.MYSQL_HOST,
|
||||
port: process.env.MYSQL_PORT,
|
||||
user: process.env.MYSQL_USER,
|
||||
password: process.env.MYSQL_PASSWORD,
|
||||
database: process.env.MYSQL_DATABASE
|
||||
})
|
||||
|
||||
// Retrieve the count of rewards claimed by each user, sorted by count
|
||||
let results = await connection.execute('SELECT * FROM rewards ORDER BY count DESC')
|
||||
.then(async ([rows, fields]) => { return rows })
|
||||
.catch(error => { console.error(error) })
|
||||
|
||||
// Terminate the connection to the database
|
||||
await connection.end()
|
||||
|
||||
if (!results) return { error: 'No scoreboard data found' }
|
||||
return results
|
||||
}
|
||||
Reference in New Issue
Block a user