-
Notifications
You must be signed in to change notification settings - Fork 5
/
batch.roc
58 lines (50 loc) · 1.78 KB
/
batch.roc
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
app [main] {
pg: "../src/main.roc",
pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.15.0/SlwdbJ-3GR7uBWQo6zlmYWNYOxnvo8r6YABXD-45UOw.tar.br",
}
import pf.Stdout
import pg.Pg.Cmd
import pg.Pg.BasicCliClient
import pg.Pg.Batch
import pg.Pg.Result
main =
client = Pg.BasicCliClient.connect! {
host: "localhost",
port: 5432,
user: "postgres",
auth: None,
database: "postgres",
}
Stdout.line! "Connected!"
resultWith =
Pg.Batch.succeed (\hi -> \eleven -> \thirtyOne -> { hi, fortyTwo: eleven + thirtyOne })
|> Pg.Batch.with
(
Pg.Cmd.new "select 'hi' as value"
|> Pg.Cmd.expect1 (Pg.Result.str "value")
)
|> Pg.Batch.with
(
Pg.Cmd.new "select $1::int as value"
|> Pg.Cmd.bind [Pg.Cmd.u8 11]
|> Pg.Cmd.expect1 (Pg.Result.u8 "value")
)
|> Pg.Batch.with
(
Pg.Cmd.new "select $1::int as value"
|> Pg.Cmd.bind [Pg.Cmd.u8 31]
|> Pg.Cmd.expect1 (Pg.Result.u8 "value")
)
|> Pg.BasicCliClient.batch! client
str42 = Num.toStr resultWith.fortyTwo
Stdout.line! "$(resultWith.hi) $(str42)"
resultSeq =
List.range { start: At 0, end: At 20 }
|> List.map \num ->
Pg.Cmd.new "select $1::int as value"
|> Pg.Cmd.bind [Pg.Cmd.u8 num]
|> Pg.Cmd.expect1 (Pg.Result.u8 "value")
|> Pg.Batch.sequence
|> Pg.BasicCliClient.batch! client
resultSeqStr = resultSeq |> List.map Num.toStr |> Str.joinWith ", "
Stdout.line resultSeqStr