forked from databricks/databricks-sql-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession.js
66 lines (53 loc) · 1.74 KB
/
session.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
const { DBSQLClient } = require('../');
const client = new DBSQLClient();
const utils = DBSQLClient.utils;
const host = '****.databricks.com';
const path = '/sql/1.0/endpoints/****';
const token = 'dapi********************************';
client
.connect({ host, path, token })
.then(async (client) => {
const session = await client.openSession();
await createTables(session);
const typeInfo = await session.getTypeInfo().then(handleOperation);
console.log(typeInfo);
console.log();
const catalogs = await session.getCatalogs().then(handleOperation);
console.log(catalogs);
console.log();
const schemas = await session.getSchemas({}).then(handleOperation);
console.log(schemas);
console.log();
const tables = await session.getTables({}).then(handleOperation);
console.log(tables);
console.log();
const tableTypes = await session.getTableTypes({}).then(handleOperation);
console.log(tableTypes);
console.log();
const columns = await session.getColumns({}).then(handleOperation);
console.log(columns);
console.log();
await session.close();
await client.close();
})
.catch((error) => {
console.log(error);
});
async function handleOperation(operation) {
const result = await operation.fetchAll({
progress: true,
callback: (stateResponse) => {
console.log(stateResponse.taskStatus);
},
});
await operation.close();
return result;
}
const createTables = async (session) => {
await session
.executeStatement('CREATE TABLE IF NOT EXISTS table1 ( id STRING, value INTEGER )')
.then(handleOperation);
await session
.executeStatement('CREATE TABLE IF NOT EXISTS table2 ( id STRING, table1_fk INTEGER )')
.then(handleOperation);
};