QueriesExamples

Query Examples

These queries come from the Concert App tutorial.


Shows for followed artists

Join artist_show_directory with user_following:

queries:
  shows_for_followed_artists:
    from: artist_show_directory
    joins:
      user_following:
        on:
          artist_show_directory.artist_id: user_following.artist_id
        fields:
          - user_following.user_id
    fields:
      - artist_show_directory.*
    input:
      user_id: { type: string, required: true }
    where:
      user_following.user_id: { eq: input.user_id }
    order_by:
      date: asc
    limit: 50
curl -X POST "http://localhost:8082/v1/platforms/my-platform/applications/concert-app/forks/main/queries/shows_for_followed_artists" \
  -H "Content-Type: application/json" \
  -d '{"params": {"user_id": "user-123"}}'

Artist leaderboard (cached)

queries:
  artist_leaderboard:
    from: artist_leaderboard
    fields:
      - artist_id
      - artist_name
      - attend_count
    order_by:
      attend_count: desc
    limit: 20
    cache_ttl_seconds: 60

Good candidate for caching — public leaderboard data tolerates brief staleness.


User ticket history

queries:
  user_ticket_history:
    from: show_attendance
    input:
      user_id: { type: string, required: true }
    where:
      user_id:  { eq: input.user_id }
      refunded: { eq: false }
    order_by:
      purchased_at: desc
    limit: 100

Show revenue (aggregate)

queries:
  show_revenue:
    from: show_attendance
    input:
      show_id: { type: string, required: true }
    where:
      show_id:  { eq: input.show_id }
      refunded: { eq: false }
    group_by: [show_id]
    aggregate:
      total_revenue_cents: { sum: price_cents }
      tickets_sold:        { count: ticket_id }
    coalesce_zero: true
    limit: 1

Unread notification count

queries:
  unread_notification_count:
    from: user_notifications
    input:
      user_id: { type: string, required: true }
    where:
      user_id: { eq: input.user_id }
      read:    { eq: false }
    group_by: [user_id]
    aggregate:
      count: { count: notification_id }
    coalesce_zero: true
    limit: 1

See User Notifications for the full action + projection + query flow.


More examples

ExampleQueries demonstrated
Concert AppFull query catalog with curl examples
Your First QueryConcert app join query end-to-end
Complete Concert AppFull assemble, compile, deploy, run
Rebuilding ProjectionsQuery behavior after projection rebuild

Next steps