forked from zio/zio-sql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Example1.scala
49 lines (35 loc) · 1.09 KB
/
Example1.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
import zio.sql.Sql
object Example1 extends Sql {
import ColumnSet._
def renderRead(read: this.Read[_]): String = ???
def renderDelete(delete: this.Delete[_]): String = ???
def renderUpdate(update: Example1.Update[_]): String = ???
val columnSet = int("age") ++ string("name")
val table = columnSet.table("person")
val table2 = columnSet.table("person2")
val age :*: name :*: _ = table.columns
val age2 :*: name2 :*: _ = table2.columns
import FunctionDef._
import AggregationDef._
val queried =
(select {
((age + 2) as "age") ++ (name as "name") ++ (Abs(3.0) as "dummy")
} from table)
.limit(200)
.offset(1000)
.orderBy(age.descending)
val joined =
select {
(age as "age") ++ (age2 as "age2")
} from (table join table2).on(name === name2)
val aggregated =
(select {
(Arbitrary(age) as "age") ++ (Count(1) as "count")
} from table) groupBy age
//val deleted = deleteFrom(table).where(age === 3)
val updated =
update(table)
.set(age, age + 2)
.set(name, "foo")
.where(age > 100)
}