How do i return "0" when ther is n ovalue set in sqllite

So basically I made a system which checks someone Rating based on behaviour on the discord server but idk how to make it so when there is no sqllite set because they dont have a bad past it returns 0

aslo if you are wondering the rating system is meant lower is better

this is my code
function getRating(userID) {
return WarnSys.get(userID+"_Rating") || β€œ0”
}
warnsys is a database made with endb

You could try checking if the value is null

1 Like

@TheDooM

You can use Endb#has to see if a value exists and return values accordingly.

async function getRating(userID) {
  if(!await WarnSys.has(userID)) {
    return "0";
  } else {
    return await WarnSys.get(userID + "_Rating")
  }
}

Hope this helps!

1 Like

it helped but it says Promise { } the value i stored is β€œ3”

Use async/await functions to solve the Promises.

1 Like

i used the code you sent me and it uses await

this is my test code rn WarnSys.set("480805672057962516_Rating", "1") async function getRating(userID) { if(!await WarnSys.has(userID)) { return "0"; } else { return await WarnSys.get(userID + "_Rating") } } console.log(getRating("480805672057962516"));

1 Like

When you use Endb, it is recommended to use async/await to resolve Promises.

1 Like

@TheDooM, @chroventer (who made Endb) has asked you to join Endb’s Discord server so that he might be able to help you better: https://discord.gg/d5SYmjj

1 Like