squeal icon indicating copy to clipboard operation
squeal copied to clipboard

LINQ style queries in Squeal?

Open echatav opened this issue 3 years ago • 1 comments

The question recently was asked at work:

Have you considered putting the select at the end instead of the beginning? C#’s LINQ ended up making that change in its approach to a SQL-like DSL. Not sure it would help but I was curious if you considered that approach or not.

I hadn't considered it at all but in fact, with more thorough use of the reverse function application operator (&), Squeal already supports this LINQ style:

-- LINQ style
from (table #scores)
  & where_ (#score .> 80)
  & groupBy #winner
  & select_
    ( #winner :*
      max_ #score `as` #best_score
    )

-- SQL style
select_
  ( #winner :*
    max_ #score `as` #best_score
  )
  ( from (table #scores)
    & where_ (#score .> 80)
    & groupBy #winner
  )

echatav avatar Mar 09 '21 16:03 echatav

Brilliant 👏🏻

gasi avatar Dec 02 '23 22:12 gasi