Capabilities
Database Queries
Imported from the upstream Vibescript examples at capabilities/database_queries.vibe and runnable in the browser today.
Source
capabilities/database_queries.vibe
# vibe: 0.2
# uses: db
def load_player(id)
db.find("Player", id)
end
def top_players(limit)
db.query("Player", order: { raised: :desc }, limit: limit)
end
def increment_total(id, amount)
player = db.find("Player", id)
updated = player[:raised] + amount
db.update("Player", id, { raised: updated })
end
def run
{
note: "This example requires the db capability which is injected by the host application.",
functions: ["load_player", "top_players", "increment_total"]
}
end
Output
Press run to execute run from this example.