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]);
}
}