Files
bot_Laytho/utils/getRewardData.js

23 lines
777 B
JavaScript

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
}