Install the following dependencies from the npm package registry
npm install -S @exasol/exasol-driver-ts ws @types/ws
Connecting to the database:
import { ExasolDriver,ExaWebsocket } from '@exasol/exasol-driver-ts';
import { WebSocket } from 'ws';
const driver = new ExasolDriver((url) => {
return new WebSocket(url) as ExaWebsocket;
}, {
host: "localhost",
port: 8563,
user: 'sys',
password: 'exasol',
encryption: false,
});
//connect
await driver.connect();
//execute query
await driver.query("SELECT * FROM EXA_ALL_SCHEMAS");
//close the connection
await driver.close();
Install the following dependencies from the npm package registry
npm install -S @exasol/exasol-driver-ts
Connecting to the database:
import { ExasolDriver,ExaWebsocket } from '@exasol/exasol-driver-ts';
const driver = new ExasolDriver((url) => {
return new WebSocket(url) as ExaWebsocket;
}, {
host: "localhost",
port: 8563,
user: 'sys',
password: 'exasol',
encryption: false,
});
await driver.connect();
await driver.query("SELECT * FROM EXA_ALL_SCHEMAS")
await driver.close();
Executing a query using the query method:
//...
//connect
await driver.connect();
//execute query
await driver.query('SELECT * FROM EXA_ALL_SCHEMAS');
//close the connection
await driver.close();
Executing a command using the command method (creating a schema, table and inserting some values):
//...
//connect
await driver.connect();
const schemaName = 'TEST';
//execute commands
await driver.execute('CREATE SCHEMA ' + schemaName);
await driver.execute('CREATE TABLE ' + schemaName + '.TEST_TABLE(x INT)');
await driver.execute('INSERT INTO ' + schemaName + '.TEST_TABLE VALUES (15)');
//close the connection
await driver.close();
Running a query and retrieving the results:
//...
//connect
await driver.connect();
const schemaName = 'TEST';
//run the query
const queryResult = await driver.query('SELECT x FROM ' + schemaName + '.TEST_TABLE');
//print the result
console.log(queryResult.getColumns());
/*
[
{ name: 'X', dataType: { type: 'DECIMAL', precision: 18, scale: 0 } }
]
*/
console.log(queryResult.getRows());
/*
[ { X: 15 } ]
*/
//close the connection
await driver.close();
Reading out a specific row and column from the result set:
const queryResult = await driver.query('...');
//print out the 0th row, 'X' column value
console.log(queryResult.getRows()[0]['X']);
Property | Value | Default | Description |
---|---|---|---|
host |
string | 'localhost' | Host name or ip address. |
port |
number | 8563 | Port number. |
user |
string | Exasol username. | |
password |
string | Exasol password. | |
autocommit |
false=off, true=on | true | Switch autocommit on or off. |
clientName |
string | 'Javascript client' | Tell the server the application name. |
clientVersion |
string | 1 | Tell the server the version of the application. |
encryption |
false=off, true=on | true | Switch automatic encryption on or off. |
fetchSize |
number, >0 | 128*1024 |
Amount of data in kB which should be obtained by Exasol during a fetch. The application can run out of memory if the value is too high. |
resultSetMaxRows |
number | Set the max amount of rows in the result set. | |
schema |
string | Exasol schema name. |
As of version 0.2.0 we now also provide a connection pool called ExasolPool
.
Install the following dependencies from the npm package registry:
NodeJS:
npm install --save @exasol/exasol-driver-ts ws @types/ws
Browser:
npm install --save @exasol/exasol-driver-ts
NodeJs:
import { ExaWebsocket, ExasolPool } from "@exasol/exasol-driver-ts";
import { WebSocket } from 'ws';
const pool = new ExasolPool((url) => {
return new WebSocket(url) as ExaWebsocket;
}, {
host: 'localhost',
port: 8563,
user: 'sys',
password: 'exasol',
encryption: false,
minimumPoolSize: 1,
maximumPoolSize: 10,
});
Browser:
import { ExasolDriver,ExaWebsocket } from '@exasol/exasol-driver-ts';
const pool = new ExasolPool((url) => {
return new WebSocket(url) as ExaWebsocket;
}, {
host: 'localhost',
port: 8563,
user: 'sys',
password: 'exasol',
encryption: false,
minimumPoolSize: 1,
maximumPoolSize: 10,
});
The configuration is very similar to the ExasolDriver
(client). With the added minimumPoolSize
and maximumPoolSize
options you can specify the minimum and maximum number of active connections in the pool. Defaults are 0 (minimumPoolSize) and 5 (maximumPoolSize).
const queryResult = await pool.query('SELECT x FROM SCHEMANAME.TABLENAME');
Draining and clearing the pool (do this when you don't need the pool anymore or before exiting the application):
await pool.drain();
await pool.clear();
Property | Value | Default | Description |
---|---|---|---|
host |
string | 'localhost' | Host name or ip address. |
port |
number | 8563 | Port number. |
user |
string | Exasol username. | |
password |
string | Exasol password. | |
autocommit |
false=off, true=on | true | Switch autocommit on or off. |
clientName |
string | 'Javascript client' | Tell the server the application name. |
clientVersion |
string | 1 | Tell the server the version of the application. |
encryption |
false=off, true=on | true | Switch automatic encryption on or off. |
fetchSize |
number, >0 | 128*1024 |
Amount of data in kB which should be obtained by Exasol during a fetch. The application can run out of memory if the value is too high. |
resultSetMaxRows |
number | Set the max amount of rows in the result set. | |
schema |
string | Exasol schema name. | |
minimumPoolSize |
number | 0 | Minimum amount of active connections. |
maximumPoolSize |
number | 5 | Maximum amount of active connections. |