Capabilities

Database Queries

Query and update data through a database API from the Go app.

Reference View source
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 example to run this code.