Once you have installed the driver and set up an Ultipa instance, you can connect your application to the database.
You can establish a connection using the configurations from UltipaConfig
. See UltipaConfig Attributes.
Creating a Connection
Creates a connection using ConnectionPool()
:
import { ConnectionPool } from "@ultipa-graph/ultipa-node-sdk5";
import { ULTIPA } from "@ultipa-graph/ultipa-node-sdk5";
let sdkUsage = async () => {
// URI example: ultipaConfig.hosts: ["https://mqj4zouys.us-east-1.cloud.ultipa.com:60010"]
const ultipaConfig: ULTIPA.UltipaConfig = {
hosts: ["192.168.1.85:60061", "192.168.1.86:60061", "192.168.1.87:60061"],
username: "<username>",
password: "<password>",
};
const conn = await new ConnectionPool(
ultipaConfig.hosts,
ultipaConfig.username,
ultipaConfig.password
).getActive();
// Tests the connection
const isSuccess = await conn.test();
console.log(`Connection succeeds: ${isSuccess}`);
};
sdkUsage().catch(console.error);
Connection succeeds: true
Using Configuration File
This example demonstrates how to use the configuration file .env
to establish a connection:
import { ULTIPA,ConnectionPool} from '@ultipa-graph/ultipa-node-sdk5';
import * as dotenv from "dotenv";
// Loads the .env file and overrides system environment variables
dotenv.config({override:true});
const hosts = process.env.hosts?.split(',') || [];
const username = process.env.username!;
const password = process.env.password!;
const sdkUsage = async () => {
const connPool = new ConnectionPool(hosts, username, password);
const conn = await connPool.getActive();
// Tests the connection
const isSuccess = await conn.test();
console.log(`Connection succeeds: ${isSuccess}`);
};
sdkUsage().catch(console.error);
Connection succeeds: true
Example of the .env
file:
// hosts=https://mqj4zouys.us-east-1.cloud.ultipa.com:60010
hosts=192.168.1.85:60061,192.168.1.86:60061,192.168.1.87:60061
username=<username>
password=<password>
passwordEncrypt=MD5
defaultGraph=miniCircle
// crt=F:\\ultipa.crt
// maxRecvSize=10240
UltipaConfig Attributes
The UltipaConfig
class includes the following attributes:
Attribute |
Type |
Default |
Description |
---|---|---|---|
hosts |
string[] | / | Required. A comma-separated list of database server IPs or URLs. If a URL does not start with https:// or http:// , http:// is prefixed by default. |
username |
string | / | Required. Username of the host authentication. |
password |
string | / | Required. Password of the host authentication. |
defaultGraph |
string | / | Name of the graph to use by default in the database. |
crt |
string | / | The file path of the SSL certificate used for secure connections. |
passwordEncrypt |
string | MD5 |
Password encryption method of the driver. Supports MD5 , LDAP and NOTHING . |
timeout |
number | 15 | Connection timeout threshold (in second). |
heartBeat |
number | 0 | The heartbeat interval (in millisecond), used to keep the connection alive. Set to 0 to disable. |
maxRecvSize |
number | 32 | The maximum size (in MB) of the received data. |