YAML -> SQL

YAML

    

declare:
  eql:
    operator: =
    left: $1
    value: $2
  get_sum: 
    operator: $1
  sum:
    apply: ["get_sum", "sum"]
    args:
    - $1
  group_by:
    field: $1
main:
  from: payments
  alias: p
  distinct: true
  select:
  - apply: ["sum", "i.views"]
  - apply: ["sum", "i.clicks"]
  - apply: ["sum", "p.amount"]
  where:
  - apply: ["eql", "user_id", "12"]
  group:
  - apply: ["group_by", "date"]
  
    
    

SQL

    
SELECT DISTINCT SUM(i.views), SUM(i.clicks), SUM(p.amount) FROM "payments" "p" WHERE user_id = 12 GROUP BY date