Public
Edited
Sep 13, 2024
5 stars
Insert cell
Insert cell
demo = HeavyAIDatabaseClient.open({
protocol: "https",
host: "demo-flights.heavy.ai",
port: "443",
dbName: "newflights",
user: "demouser",
password: "HyperInteractive"
})
Insert cell
demo.describe()
Insert cell
demo
SELECT carrier_name, AVG(airtime) AS avg_airtime
FROM flights
WHERE airtime IS NOT NULL
GROUP BY carrier_name
ORDER BY avg_airtime DESC
Insert cell
demo
SELECT COUNT(*) AS "count"
FROM flights
WHERE airtime IS NOT NULL
Insert cell
Plot.plot({
marginLeft: 150,
y: {
label: null
},
marks: [
Plot.barX(flights, {x: "avg_airtime", y: "carrier_name", sort: {y: "x"}}),
Plot.ruleX([0])
]
})
Insert cell
Insert cell
class HeavyAIDatabaseClient {
static async open({
protocol = "https",
port = protocol === "https" ? "443" : undefined,
host,
dbName,
user,
password
} = {}) {
const connector = new HeavyAI.DbCon();
if (protocol !== undefined) connector.protocol(protocol);
if (host !== undefined) connector.host(host);
if (port !== undefined) connector.port(port);
if (dbName !== undefined) connector.dbName(dbName);
if (user !== undefined) connector.user(user);
if (password !== undefined) connector.password(password);
return new HeavyAIDatabaseClient(await connector.connectAsync());
}
constructor(connector) {
Object.defineProperty(this, "connector", {value: connector});
}
async describe(name) {
if (name !== undefined) {
const fields = await this.connector.getFieldsAsync(name);
const table = htl.html`<table>
<thead><tr><th>name</th><th>type</th><th>precision</th><th>is_array</th><th>is_dict</th></tr></thead>
<tbody>${fields.columns.map(c => htl.html`<tr>
<td>${c.name}</td>
<td>${c.type}</td>
<td>${c.precision}</td>
<td>${c.is_array}</td>
<td>${c.is_dict}</td>
</tr>`)}</tbody>
</table>`;
table.value = fields.columns;
return table;
}
const tables = await this.connector.getTablesAsync();
const table = htl.html`<table>
<thead><tr><th>name</th><th>label</th></tr></thead>
<tbody>${tables.map(t => htl.html`<tr>
<td>${t.name}</td>
<td>${t.label}</td>
</tr>`)}</tbody>
</table>`;
table.value = tables;
return table;
}
async sql(strings, ...args) {
if (strings.length > 1) throw new Error("query parameters not supported");
return this.connector.queryAsync(strings[0]);
}
}
Insert cell
MapDDatabaseClient = HeavyAIDatabaseClient // for backwards compatibility
Insert cell
HeavyAI = (await import("https://cdn.jsdelivr.net/npm/@heavyai/connector@7/+esm")).default
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more