-
Notifications
You must be signed in to change notification settings - Fork 40
/
node.js
69 lines (60 loc) · 2.11 KB
/
node.js
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
/* eslint-disable */
const Connector = require("../dist/node-connector.js")
const hostname = process.env.HOSTNAME || "metis.mapd.com"
const protocol = process.env.PROTOCOL || "https"
const port = process.env.PORT || "443"
const database = process.env.DATABASE || "mapd"
const username = process.env.USERNAME || "mapd"
const password = process.env.PASSWORD || "HyperInteractive"
// The total number of tweets from Columbia
const query = "SELECT count(*) AS n FROM tweets_nov_feb WHERE country='CO'"
const query2 =
"SELECT carrier_name as key0, AVG(airtime) AS val FROM flights_donotmodify WHERE airtime IS NOT NULL GROUP BY key0 ORDER BY val DESC LIMIT 100"
const defaultQueryOptions = {}
const connector = new Connector()
connector
.protocol(protocol)
.host(hostname)
.port(port)
.dbName(database)
.user(username)
.password(password)
.connectAsync()
.then(session =>
// now that we have a session open we can make some db calls:
Promise.all([
session.getDashboardsAsync(),
session.getTablesAsync(),
session.getFieldsAsync("flights_donotmodify"),
session.queryAsync(query, defaultQueryOptions),
session.queryAsync(query2, defaultQueryOptions)
])
)
// values is an array of results from all the promises above
.then(values => {
// handle result of getDashboardsAsync
console.log(
`All dashboards available at ${hostname}:\n`,
values[0].map(dash => dash.dashboard_name)
)
// handle result of getTablesAsync
console.log(
`\nAll tables available at ${hostname}:\n\n`,
values[1].map(x => x.name)
)
// handle result of getFieldsAsync
console.log(
"\nAll fields for 'flights_donotmodify':\n\n",
values[2].columns.reduce((o, x) => Object.assign(o, { [x.name]: x }), {})
)
// handle result of first query
console.log("\nQuery 1 results:\n\n", Number(values[3][0].n))
// handle result of second query
console.log(
"\nQuery 2 results:\n\n",
values[4].reduce((o, x) => Object.assign(o, { [x.key0]: x.val }), {})
)
})
.catch(error => {
console.error("Something bad happened: ", error)
})