Let's start with the real job! Get all the data, get some bits and sort the data!
Get all the data
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 =awaittable.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 filterlet filter =newclient.filter(null,"and");filter.add("mail","@gmail.com","ends");// Getting the information from the databaselet gmails =awaittable.where(filter);// Everyone with a gmail address is now in the variable "gmails"!
// Making the filterlet filter =newclient.filter(null);filter.add("mail","@gmail.com","ends");// Getting the information from the databaselet gmails =table.where(filter).then(gmails => {// Everyone with a gmail address is now in the variable "gmails"!});
For more explanation about filters, view the using a filter 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 =newclient.filter(10);// Requestinglet leaderboard =awaittable.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 =newclient.filter(10);// Requestingtable.sort(["level","points"], filter).then(leaderboard => { // First sort on the level, then on the points// Here you have to handle the sending.});