forked from zio/zio-sql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GroupByExamples.scala
76 lines (56 loc) · 1.71 KB
/
GroupByExamples.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package zio.sql
import zio.schema.DeriveSchema
import zio.sql.postgresql.PostgresJdbcModule
object GroupByExamples extends App with PostgresJdbcModule {
import AggregationDef._
case class Product(id: Int, name: String, amount: Int, price: Double)
implicit val productSchema = DeriveSchema.gen[Product]
val productTable = defineTable[Product]
val (id, name, amount, price) = productTable.columns
select(Count(price))
.from(productTable)
.groupBy(price)
val e = Sum(price) > 10
def testF[F, A, B](value: Expr[F, A, B])(implicit in: Features.IsFullyAggregated[F]) = ???
def test2[F, A, B](value: Expr[F, A, B])(implicit i: Features.IsPartiallyAggregated[F]): i.Unaggregated = ???
val orderValue = select(name, Sum(price))
.from(productTable)
.groupBy(name, price)
.having(Sum(price) > 10)
select(Sum(price))
.from(productTable)
.groupBy(name)
.having(Sum(price) > 10)
select(name, amount, price)
.from(productTable)
.groupBy(name, amount, price)
.having(Sum(price) > 10)
select(amount)
.from(productTable)
.groupBy(amount)
.having(amount > 10)
select(Sum(price))
.from(productTable)
.groupBy(name)
.having(name > "z")
select(price)
.from(productTable)
.groupBy(price)
.having(Count(price) > 10)
// Following should not compile
// select(amount ++ price)
// .from(productTable)
// .groupBy(amount)
// .having(amount > 10)
// select(price)
// .from(productTable)
// .groupBy(name)
// .having(name > 10)
// select(price ++ name)
// .from(productTable)
// .groupBy(price)
// .having(Count(price) > 10)
// select(price)
// .from(productTable)
// .having(Count(price) > 10)
}