K
Docs
API Reference→Pieces→Find Rank
🥇

Find Rank

vault.rankThe VaultVault

Finds one row's place when the table is sorted by a column — without fetching the whole leaderboard. Ties share a place, like a real scoreboard. Gives you {{rank.place}}, {{rank.total}} and {{rank.value}}.

When to use this
  • →Two people on the same score share a place — the next one skips ahead (#3, #3, #5)
  • →{{rank.total}} counts every row in the table

On the canvas

This is what Find Rank looks like when you place it on your flow. Each field below is something you configure in the inspector panel.

🥇
Find Rank
vault.rank
Vault
tablerequired
Pick a table…
columnrequired
e.g. xp
order
select…
keyrequired
{{input.user.id}}
asrequired
rank
found
missing

Config fields

FieldTypeReqWhat it does
table
Pick a table…
textyesTable 🗄️
column
e.g. xp
textyesRank by 🏆
orderselect—Which way 🔃
key
{{input.user.id}}
textyesWhose rank 🔑
as
rank
textyesSave it as ✨

Output ports

foundTheir row exists — {{rank.place}} is their spot
missingThey don't have a row yet
📐

In TypeScript, this would be…

Not something you need to write — just a look at what Kitcord does for you.

TypeScript
const mine = await db.get("SELECT xp FROM levels WHERE user_id = ?", [userId]);
const ahead = await db.get("SELECT COUNT(*) AS n FROM levels WHERE xp > ?", [mine.xp]);
const total = await db.get("SELECT COUNT(*) AS n FROM levels");
// {{rank.place}} = ahead.n + 1, {{rank.total}} = total.n, {{rank.value}} = mine.xp