Skip to content

Repository files navigation

IoTDB Client for Node.js

This is a modern Node.js client library for IoTDB, inspired by popular database clients like Prisma and InfluxDB. It aims to provide an intuitive, type-safe interface for interacting with IoTDB using modern JavaScript/TypeScript idioms.

⚠️ Status: Early Preview This library is in its early development stages. The API is subject to change, and many features are yet to be implemented. Contributions, suggestions, and bug reports are welcome as we evolve the library.


Features

  • TypeScript-first: Type-safe queries and operations.
  • Session Management: Automatic session handling for convenience and reliability.
  • Flexible Operations: Create, delete, and update time series and measurements.
  • Inspired Design: Built with a Prisma and InfluxDB-like approach.

Installation

npm install iotdb-client

Usage Example

Here’s a basic example demonstrating how to create a client, connect to IoTDB, and perform simple operations:

import{IoTDBClient,DataType}from'iotdb-client';asyncfunctionmain(){// Create a new client instanceconstclient=newIoTDBClient('127.0.0.1',6667,{username: 'root',password: 'root',});try{// Connect to the IoTDB serverawaitclient.$connect();console.log('Connected to IoTDB.');// Create a time series - creates a temporary session and closes itawaitclient.createTimeSeries('root.vehicle.d0.s0',DataType.INT32,{description: 'Temperature sensor'},);console.log('Time series created.');// Insert a measurement - creates a temporary session and closes itawaitclient.insertMeasurement('root.vehicle.d0','s0',newDate(),25,DataType.INT32,);console.log('Measurement inserted.');// Perform custom session operationsawaitclient.$session(async(session)=>{console.log('Session started.');constqueryResult=awaitsession.rawQuery('SELECT * FROM root.vehicle.d0',);forawait(resultofqueryResult.next()){// Print the result:console.log(result)}});}catch(error){console.error('Error:',error);}finally{// Disconnect from the serverawaitclient.$disconnect();console.log('Disconnected from IoTDB.');}}main().catch((err)=>console.error('Unexpected Error:',err));

API Highlights

Client Initialization

constclient=newIoTDBClient(host,port,{ username, password, zoneId });
  • host: Hostname or IP address of the IoTDB server.
  • port: Port number (default: 6667).
  • options: Optional settings like username, password, and time zone.

Core Methods

$connect()

Connect to the IoTDB server.

$disconnect()

Disconnect from the server gracefully.

createTimeSeries(path, type, tags?, encoding?, compression?)

Creates a time series with the specified properties.

insertMeasurement(path, measurement, time, value, type?)

Insert a single measurement into a time series.

insertMeasurements(path, measurements, time, values, types?)

Insert multiple measurements into a time series.

$session(callback)

Run operations within a managed session.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

3 watching

Forks

Releases

Packages

Contributors

Languages