This section introduces the uql()
and uqlStream()
methods to execute UQL in the database.
UQL (Ultipa Query Language) is the native language designed by Ultipa to fully interact with Ultipa graph databases. For detailed information on UQL, refer to the documentation.
uql()
Executes a UQL query in the database.
Parameters
uql: string
: The UQL query to be executed.config: RequestConfig
(Optional): Request configuration.
Returns
Response
: Response of the request.
// Retrieves 5 movie nodes from the graph 'miniCircle' and prints their names
const requestConfig: RequestConfig = {
graph: "miniCircle",
};
let response = await conn.uql(
"find().nodes({@movie}) as n return n{*} limit 5",
requestConfig
);
const nodeList = response.items?.get("n")?.asNodes();
nodeList?.forEach((node) => {
console.log(node.get("name"));
});
The Shawshank Redemption
Farewell My Concubine
Léon: The Professional
Titanic
Life is Beautiful
uqlStream()
Executes an UQL query in the database and returns the results incrementally, allowing handling of large datasets without loading everything into memory at once.
Parameters
uql: string
: The UQL query to be executed.cb: RequestType.QueryResponseListener
: Listener for the streaming process.config: RequestConfig
(Optional): Request configuration.
Returns
None
// Retrieves all 1-step paths from the graph 'miniCircle'
const requestConfig: RequestConfig = {
graph: "miniCircle",
};
let count = 0;
let response = await conn.uqlStream(
"n().e().n() as p return p{*}",
// Define the event handler functions
{
onStart: () => {
console.log("Stream started.")
},
onData: async (res) => {
let paths = res.items?.get("p")?.asPaths();
count = count + (paths?.length || 0);
console.log(count);
},
onEnd: () => {
console.log("Stream ended.");
},
onError: (err) => {
console.log(err);
}
},
requestConfig
);
Stream started.
1024
2048
3072
3227
3464
3895
Stream ended.
Full Example
import { UltipaDriver } from "@ultipa-graph/ultipa-driver";
import { ULTIPA } from "@ultipa-graph/ultipa-driver/dist/types";
let sdkUsage = async () => {
// URI example: ultipaConfig.hosts: ["mqj4zouys.us-east-1.cloud.ultipa.com:60010"]
const ultipaConfig: ULTIPA.UltipaConfig = {
hosts: ["192.168.1.85:60061", "192.168.1.87:60061", "192.168.1.88:60061"],
username: "<username>",
password: "<password>"
};
const conn = new UltipaDriver(ultipaConfig);
const isSuccess = await conn.test();
console.log(`Connection succeeds: ${isSuccess}`);
const requestConfig: ULTIPA.RequestConfig = {
graph: "miniCircle",
};
// Retrieves 5 movie nodes from the graph 'miniCircle' and prints their names
let response = await conn.uql(
"find().nodes({@movie}) as n return n{*} limit 5",
requestConfig
);
let nodeList = response.items?.get("n")?.asNodes();
nodeList?.forEach((node) => {
console.log(node.get("name"));
});
};
sdkUsage().catch(console.error);