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.
- 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.
npm install iotdb-clientHere’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));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.
Connect to the IoTDB server.
Disconnect from the server gracefully.
Creates a time series with the specified properties.
Insert a single measurement into a time series.
Insert multiple measurements into a time series.
Run operations within a managed session.