zio / zio-quill

Compile-time Language Integrated Queries for Scala
https://zio.dev/zio-quill
Apache License 2.0
2.15k stars 346 forks source link

DSH Support #156

Closed freddie-freeloader closed 7 years ago

freddie-freeloader commented 8 years ago

I'm currently assessing whether I can use quill as an interface for DSH.

DSH exposes a Module that


Quill and CL comparison:


Simple query Quill

case class Person(id: Int, name: String)

val q = quote {
  for {
    p <- query[Person] 
  } yield p.name 
} 

CL

-- Definition of table:
let t = table(person, [id::Int, name::String], [[id]])::[(Int,String)] 
                                            -- ^^^^^^
in                                          -- Keys
-- Query:
[ (p.name)::String | p <- t ]             

Query with nested result Quill

case class Person(name: String, age: Int)

val q = quote {
  for {
    p1 <- query[Person]
  } yield {
    ( for {
      p2 <- query[Person]
    } yield (p1.age + p2.age)
    , p1.name )
  }
}

CL

-- name and age form a key:
let t = table(person, [name::String, age::Int], [[name,age]])::[(String,Int)] 
in
[ ( [ (p1.age)::Int + (p2.age)::Int | p2 <- t ], (p1.name)::String ) | p1 <- t ] 

-- Result will be of type [([Int],String)]

Conclusion

As far as I understand Quill, these things are missing in order to create this kind of CL expressions:

fwbrasil commented 8 years ago

@freddie-freeloader Thanks for the examples, it makes more sense to me now. These changes are relatively simple to implement, I'll comment on the issues.