I am in need of creating an online leaderboard for a video game utilizing a Mobile Service on Azure. The goal is to have a table that only holds the top 100 scores, so as new scores are added, they should be admitted until reaching this limit. In order to achieve this, I must incorporate code within my insert script on Azure that counts the number of rows in my Leaderboard table.
The current default script looks like this:
function insert(item, user, request) {
request.execute();
}
To count the rows, my query would resemble something along these lines:
SELECT COUNT (*)
FROM Leaderboard
Although I attempted using mssql.query, it appears that this portion of the code is not being recognized.
var sql = "SELECT COUNT (*) FROM Leaderboard";
mssql.query(sql, {
success: function(results){
//do things
},
error: function(err) {
console.log("error: " + err);
}
});
Another approach I tried involved:
var LeaderboardOnlineTable = tables.getTable('LeaderboardOnline');
LeaderboardOnlineTable.take(0).includeTotalCount().read().then(function (results) {
var count = results.totalCount;
});
Could there be an error in my methods? Any help or advice is greatly appreciated!
Thank you in advance!