-
Notifications
You must be signed in to change notification settings - Fork 5
/
example-db-snowflake.main.kts
executable file
·55 lines (48 loc) · 1.82 KB
/
example-db-snowflake.main.kts
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
#!/usr/bin/env kotlin
// Uncomment to use mavenLocal. Run `./gradlew publishToMavenLocal -Pskip.signing=true`
//@file:Repository("file:///Users/username/.m2/repository/")
@file:DependsOn("com.shoprunner:baleen-script:1.14.1")
@file:DependsOn("net.snowflake:snowflake-jdbc:3.13.1")
import com.shoprunner.baleen.*
import com.shoprunner.baleen.Baleen.describeAs
import com.shoprunner.baleen.printer.*
import com.shoprunner.baleen.script.*
import com.shoprunner.baleen.types.*
import java.io.File
val desc = "person".describeAs {
"id".type(IntegerType(), required = true)
"first_name".type(StringType(0, 32), required = true)
"last_name".type(StringType(0, 32), required = true)
}.tag("ID" to withAttributeValue("ID"))
val connection = getConnection(
url = "jdbc:snowflake://account.us-east-1.snowflakecomputing.com/?warehouse=WAREHOUSE",
user = System.getenv("DATABASE_USER"),
dataSourceProperties = mapOf("authenticator" to "externalBrowser")
)
File("summary/example-db-table.html").writer().use {
validate(
description = desc,
data = table(connection, "engineer.example"),
groupBy = groupByTag("table"),
printers = arrayOf(ConsolePrinter, HtmlPrinter(it)),
)
}
File("summary/example-db-sample.html").writer().use {
validate(
description = desc,
data = sample(connection, "engineer.example", 0.5),
groupBy = groupByTag("table"),
printers = arrayOf(ConsolePrinter, HtmlPrinter(it)),
)
}
File("summary/example-db-query.html").writer().use {
validate(
description = desc,
data = query(
connection, "query example",
"SELECT id, first_name, last_name FROM engineer.example WHERE last_name = 'Smith'"
),
groupBy = groupByTag("table"),
printers = arrayOf(ConsolePrinter, HtmlPrinter(it)),
)
}