Let's start with getting all the data. If you want to get all the data, use the function table.getAll. There are no parameters that you have to use! Here is a example.
let allTheDate = await table.getAll();
// Everything is now in the variable "allTheData"
table.getAll().then(() => {
// Everything is now in the variable "allTheData"
});
Getting specific data
You can also get specific data. For that, you can use the function table.where. You have to use a filter for the one parameters.
// Making the filter
let filter = new client.filter(null, "and");
filter.add("mail", "@gmail.com", "ends");
// Getting the information from the database
let gmails = await table.where(filter);
// Everyone with a gmail address is now in the variable "gmails"!
// Making the filter
let filter = new client.filter(null);
filter.add("mail", "@gmail.com", "ends");
// Getting the information from the database
let gmails = table.where(filter).then(gmails => {
// Everyone with a gmail address is now in the variable "gmails"!
});
For more explanation about filters, view the page.
Sorting data
Let's say you have a point system in a Discord bot. And then you want to make a leader board. With Better-MySQL is that really simple! The only thing you have to do, is use the table.sort function and send the results.
For the sorting function, you have to make a filter and give the column up that you want to sort. Here a example.
// Making the filter. For the top 10 you only have to get 10 results.
let filter = new client.filter(10);
// Requesting
let leaderboard = await table.sort(["level", "points"], filter); // First sort on the level, then on the points
// Here you have to handle the sending.
// Making the filter. For the top 10 you only have to get 10 results.
let filter = new client.filter(10);
// Requesting
table.sort(["level", "points"], filter).then(leaderboard => { // First sort on the level, then on the points
// Here you have to handle the sending.
});