UltipaDocs
Try Playground
  • Introduction
    • Quick Start
    • Configuration
    • Connection and Session
    • Executing Queries
    • Graph Management
    • Transactions
    • Data Operations
    • Bulk Import
    • Data Export
    • Health and Administration
    • Response Processing
    • Data Types
    • Error Handling
    • Quick Start
    • Configuration
    • Connection and Session
    • Executing Queries
    • Graph Management
    • Transactions
    • Data Operations
    • Bulk Import
    • Data Export
    • Health and Administration
    • Response Processing
    • Data Types
    • Error Handling
    • Quick Start
    • Configuration
    • Connection and Session
    • Executing Queries
    • Graph Management
    • Transactions
    • Data Operations
    • Bulk Import
    • Data Export
    • Health and Administration
    • Response Processing
    • Data Types
    • Error Handling
    • Quick Start
    • Configuration
    • Connection and Session
    • Executing Queries
    • Graph Management
    • Transactions
    • Data Operations
    • Bulk Import
    • Data Export
    • Health and Administration
    • Response Processing
    • Data Types
    • Error Handling
  1. Docs
  2. /
  3. Ultipa Drivers
  4. /
  5. Node.js

Data Types

The GQLDB Node.js driver supports a comprehensive set of data types for storing and querying graph data. This guide covers property types, enums, and type conversions.

Property Types

The PropertyType enum defines all supported data types:

TypeScript
import { PropertyType } from 'gqldb-nodejs';

Numeric Types

TypeDescriptionJavaScript Type
INT3232-bit signed integernumber
UINT3232-bit unsigned integernumber
INT6464-bit signed integernumber
UINT6464-bit unsigned integernumber
FLOAT32-bit floating pointnumber
DOUBLE64-bit floating pointnumber
DECIMALArbitrary precision decimal{ value: string }

String Types

TypeDescriptionJavaScript Type
STRINGVariable-length stringstring
TEXTLong textstring

Boolean and Null

TypeDescriptionJavaScript Type
BOOLBoolean valueboolean
NULLNull valuenull
UNSETUnset/unknown typeundefined

Binary

TypeDescriptionJavaScript Type
BLOBBinary dataBuffer

Date and Time Types

TypeDescriptionJavaScript Type
TIMESTAMPUnix timestamp with nanosecondsDate
DATETIMEDate and time (deprecated, use TIMESTAMP)Date
DATEDate onlyDate
LOCAL_DATETIMELocal date and time{ nanos: bigint }
ZONED_DATETIMEDate and time with timezone{ nanos: bigint, offsetSeconds: number }
LOCAL_TIMELocal time of day{ nanosOfDay: bigint }
ZONED_TIMETime with timezone{ nanosOfDay: bigint, offsetSeconds: number }

Duration Types

TypeDescriptionJavaScript Type
YEAR_TO_MONTHYear-month duration{ months: number }
DAY_TO_SECONDDay-second duration{ nanos: bigint }

Geospatial Types

TypeDescriptionJavaScript Type
POINT2D geographic point{ latitude: number, longitude: number }
POINT3D3D point{ x: number, y: number, z: number }

Collection Types

TypeDescriptionJavaScript Type
LISTOrdered listany[]
SETUnordered unique setany[]
MAPKey-value mapRecord<string, any>
VECTORNumeric vector{ values: number[] }

Graph Types

TypeDescriptionJavaScript Type
NODEGraph nodeGqldbNode
EDGEGraph edgeGqldbEdge
PATHGraph pathGqldbPath

Other Types

TypeDescriptionJavaScript Type
RECORDRecord/rowobject
TABLETable dataobject
ERRORError value{ code: number, message: string }

PropertyType Enum Values

TypeScript
enum PropertyType {
  UNSET = 0,
  INT32 = 1,
  UINT32 = 2,
  INT64 = 3,
  UINT64 = 4,
  FLOAT = 5,
  DOUBLE = 6,
  STRING = 7,
  DATETIME = 8,  // Deprecated
  TIMESTAMP = 9,
  TEXT = 10,
  BLOB = 11,
  POINT = 12,
  DECIMAL = 13,
  LIST = 14,
  SET = 15,
  MAP = 16,
  NULL = 17,
  BOOL = 18,
  LOCAL_DATETIME = 19,
  ZONED_DATETIME = 20,
  DATE = 21,
  ZONED_TIME = 22,
  LOCAL_TIME = 23,
  YEAR_TO_MONTH = 24,
  DAY_TO_SECOND = 25,
  RECORD = 26,
  POINT3D = 27,
  VECTOR = 28,
  TABLE = 29,
  PATH = 30,
  ERROR = 31,
  NODE = 32,
  EDGE = 33
}

Graph Type Enum

TypeScript
enum GraphType {
  OPEN = 0,      // Schema-less graph
  CLOSED = 1,    // Schema-enforced graph
  ONTOLOGY = 2   // Ontology-enabled graph
}

Health Status Enum

TypeScript
enum HealthStatus {
  UNKNOWN = 0,
  SERVING = 1,
  NOT_SERVING = 2,
  SERVICE_UNKNOWN = 3
}

Cache Type Enum

TypeScript
enum CacheType {
  ALL = 0,
  AST = 1,
  PLAN = 2
}

Type Interfaces

Node Types

TypeScript
// Data for inserting nodes
interface NodeData {
  id: string;
  labels: string[];
  properties: Record<string, any>;
}

// Node from query results
interface Node {
  id: string;
  labels: string[];
  properties: Record<string, any>;
}

// Internal node representation
interface GqldbNode {
  id: string;
  labels: string[];
  properties: Record<string, any>;
}

Edge Types

TypeScript
// Data for inserting edges
interface EdgeData {
  id: string;
  label: string;
  fromNodeId: string;
  toNodeId: string;
  properties: Record<string, any>;
}

// Edge from query results
interface Edge {
  id: string;
  label: string;
  fromNodeId: string;
  toNodeId: string;
  properties: Record<string, any>;
}

// Internal edge representation
interface GqldbEdge {
  id: string;
  label: string;
  fromNodeId: string;
  toNodeId: string;
  properties: Record<string, any>;
}

Path Type

TypeScript
interface Path {
  nodes: Node[];
  edges: Edge[];
}

interface GqldbPath {
  nodes: GqldbNode[];
  edges: GqldbEdge[];
}

Graph Information

TypeScript
interface GraphInfo {
  name: string;
  graphType: GraphType;
  description: string;
  nodeCount: number;
  edgeCount: number;
}

Transaction Information

TypeScript
interface TransactionInfo {
  id: number;
  graphName: string;
  readOnly: boolean;
  startTime: number;
  timeout: number;
}

Schema Types

TypeScript
interface Schema {
  name: string;
  properties: PropertyDef[];
}

interface PropertyDef {
  name: string;
  type: PropertyType;
}

Table Types

TypeScript
interface Table {
  name: string;
  headers: Header[];
  rows: any[][];
}

interface Header {
  name: string;
  type: PropertyType;
}

interface Attr {
  name: string;
  type: PropertyType;
  values: any[];
}

Geospatial Types

TypeScript
interface Point {
  latitude: number;
  longitude: number;
}

interface Point3D {
  x: number;
  y: number;
  z: number;
}

TypedValue

The driver uses TypedValue internally for type-safe data transfer:

TypeScript
interface TypedValue {
  type: PropertyType;
  data: Buffer;
  isNull: boolean;
}

// Create a TypedValue
import { createTypedValue, PropertyType } from 'gqldb-nodejs';

const intValue = createTypedValue(PropertyType.INT64, 42);
const stringValue = createTypedValue(PropertyType.STRING, 'hello');

// Convert TypedValue to JavaScript value
import { typedValueToJS } from 'gqldb-nodejs';

const jsValue = typedValueToJS(intValue);  // 42

Type Conversion Examples

Working with Dates

TypeScript
// Insert with date
await client.gql(`
  INSERT (e:Event {
    _id: 'e1',
    name: 'Conference',
    date: DATE('2024-06-15'),
    startTime: DATETIME('2024-06-15T09:00:00Z')
  })
`);

// Query and convert
const response = await client.gql('MATCH (e:Event) RETURN e.date, e.startTime');
const row = response.first();
if (row) {
  const date: Date = row.get(0);  // JavaScript Date
  const startTime: Date = row.get(1);
  console.log('Event date:', date.toISOString());
}

Working with Points

TypeScript
// Insert with location
await client.gql(`
  INSERT (p:Place {
    _id: 'p1',
    name: 'Office',
    location: POINT(37.7749, -122.4194)
  })
`);

// Query and access point
const response = await client.gql('MATCH (p:Place) RETURN p.location');
const location = response.first()?.get(0);
console.log(`Lat: ${location.latitude}, Lng: ${location.longitude}`);

Working with Collections

TypeScript
// Insert with list and map
await client.gql(`
  INSERT (u:User {
    _id: 'u1',
    name: 'Alice',
    tags: ['developer', 'blogger'],
    metadata: {level: 5, premium: true}
  })
`);

// Query collections
const response = await client.gql('MATCH (u:User) RETURN u.tags, u.metadata');
const row = response.first();
if (row) {
  const tags: string[] = row.get(0);
  const metadata: Record<string, any> = row.get(1);
  console.log('Tags:', tags);
  console.log('Metadata:', metadata);
}

Working with Vectors

TypeScript
// Insert with vector
await client.gql(`
  INSERT (d:Document {
    _id: 'd1',
    title: 'Sample',
    embedding: VECTOR([0.1, 0.2, 0.3, 0.4])
  })
`);

// Query vector
const response = await client.gql('MATCH (d:Document) RETURN d.embedding');
const embedding = response.first()?.get(0);
console.log('Vector values:', embedding.values);

Complete Example

TypeScript
import { GqldbClient, createConfig, PropertyType } from 'gqldb-nodejs';

async function main() {
  const client = new GqldbClient(createConfig({
    hosts: ['192.168.1.100:9000']
  }));

  try {
    await client.login('admin', 'password');
    await client.createGraph('typeDemo');
    await client.useGraph('typeDemo');

    // Insert data with various types
    await client.gql(`
      INSERT (u:User {
        _id: 'u1',
        name: 'Alice',
        age: 30,
        balance: 1234.56,
        active: true,
        joined: DATE('2023-01-15'),
        location: POINT(40.7128, -74.0060),
        tags: ['developer', 'mentor'],
        settings: {theme: 'dark', notifications: true}
      })
    `);

    // Query and check types
    const response = await client.gql(`
      MATCH (u:User {_id: 'u1'})
      RETURN u.name, u.age, u.balance, u.active, u.joined, u.location, u.tags, u.settings
    `);

    const row = response.first();
    if (row) {
      console.log('Name (string):', row.getString(0));
      console.log('Age (number):', row.getNumber(1));
      console.log('Balance (number):', row.getNumber(2));
      console.log('Active (boolean):', row.getBoolean(3));
      console.log('Joined (Date):', row.get(4));
      console.log('Location (Point):', row.get(5));
      console.log('Tags (array):', row.get(6));
      console.log('Settings (object):', row.get(7));

      // Check property type
      console.log('\nProperty types:');
      for (let i = 0; i < response.columns.length; i++) {
        console.log(`  ${response.columns[i]}: ${PropertyType[row.getType(i)]}`);
      }
    }

    await client.dropGraph('typeDemo');

  } finally {
    await client.close();
  }
}

main().catch(console.error);