Node.js Native API
Apache IoTDB uses Thrift as a cross-language RPC-framework so access to IoTDB can be achieved through the interfaces provided by Thrift. This document will introduce how to generate a native Node.js interface that can be used to access IoTDB.
Dependents
- JDK >= 1.8
- Node.js >= 16.0.0
- Linux、Macos or like unix
- Windows+bash
Generate the Node.js native interface
- Find the
pom.xmlfile in the root directory of the IoTDB source code folder. - Open the
pom.xmlfile and find the following content:
1. <execution>
2. <id>generate-thrift-sources-python</id>
3. <phase>generate-sources</phase>
4. <goals>
5. <goal>compile</goal>
6. </goals>
7. <configuration>
8. <generator>py</generator>
9. <outputDirectory>${project.build.directory}/generated-sources-python/</outputDirectory>
10. </configuration>
11. </execution>
3. Duplicate this block and change the id, generator and outputDirectory to this:
1. <execution>
2. <id>generate-thrift-sources-nodejs</id>
3. <phase>generate-sources</phase>
4. <goals>
5. <goal>compile</goal>
6. </goals>
7. <configuration>
8. <generator>js:node</generator>
9. <outputDirectory>${project.build.directory}/generated-sources-nodejs/</outputDirectory>
10. </configuration>
11. </execution>
4. In the root directory of the IoTDB source code folder,run mvn clean generate-sources.
This command will automatically delete the files in iotdb/iotdb-protocol/thrift/target and iotdb/iotdb-protocol/thrift-commons/target, and repopulate the folder with the newly generated files.
The newly generated JavaScript sources will be located in iotdb/iotdb-protocol/thrift/target/generated-sources-nodejs in the various modules of the iotdb-protocol module.
Using the Node.js native interface
Simply copy the files in iotdb/iotdb-protocol/thrift/target/generated-sources-nodejs/ and iotdb/iotdb-protocol/thrift-commons/target/generated-sources-nodejs/ into your project.
rpc interface
1. // open a session
2. TSOpenSessionResp openSession(1:TSOpenSessionReq req);
4. // close a session
5. TSStatus closeSession(1:TSCloseSessionReq req);
7. // run an SQL statement in batch
8. TSExecuteStatementResp executeStatement(1:TSExecuteStatementReq req);
10. // execute SQL statement in batch
11. TSStatus executeBatchStatement(1:TSExecuteBatchStatementReq req);
13. // execute query SQL statement
14. TSExecuteStatementResp executeQueryStatement(1:TSExecuteStatementReq req);
16. // execute insert, delete and update SQL statement
17. TSExecuteStatementResp executeUpdateStatement(1:TSExecuteStatementReq req);
19. // fetch next query result
20. TSFetchResultsResp fetchResults(1:TSFetchResultsReq req)
22. // fetch meta data
23. TSFetchMetadataResp fetchMetadata(1:TSFetchMetadataReq req)
25. // cancel a query
26. TSStatus cancelOperation(1:TSCancelOperationReq req);
28. // close a query dataset
29. TSStatus closeOperation(1:TSCloseOperationReq req);
31. // get time zone
32. TSGetTimeZoneResp getTimeZone(1:i64 sessionId);
34. // set time zone
35. TSStatus setTimeZone(1:TSSetTimeZoneReq req);
37. // get server's properties
38. ServerProperties getProperties();
40. // CREATE DATABASE
41. TSStatus setStorageGroup(1:i64 sessionId, 2:string storageGroup);
43. // create timeseries
44. TSStatus createTimeseries(1:TSCreateTimeseriesReq req);
46. // create multi timeseries
47. TSStatus createMultiTimeseries(1:TSCreateMultiTimeseriesReq req);
49. // delete timeseries
50. TSStatus deleteTimeseries(1:i64 sessionId, 2:list<string> path)
52. // delete sttorage groups
53. TSStatus deleteStorageGroups(1:i64 sessionId, 2:list<string> storageGroup);
55. // insert record
56. TSStatus insertRecord(1:TSInsertRecordReq req);
58. // insert record in string format
59. TSStatus insertStringRecord(1:TSInsertStringRecordReq req);
61. // insert tablet
62. TSStatus insertTablet(1:TSInsertTabletReq req);
64. // insert tablets in batch
65. TSStatus insertTablets(1:TSInsertTabletsReq req);
67. // insert records in batch
68. TSStatus insertRecords(1:TSInsertRecordsReq req);
70. // insert records of one device
71. TSStatus insertRecordsOfOneDevice(1:TSInsertRecordsOfOneDeviceReq req);
73. // insert records in batch as string format
74. TSStatus insertStringRecords(1:TSInsertStringRecordsReq req);
76. // test the latency of innsert tablet,caution:no data will be inserted, only for test latency
77. TSStatus testInsertTablet(1:TSInsertTabletReq req);
79. // test the latency of innsert tablets,caution:no data will be inserted, only for test latency
80. TSStatus testInsertTablets(1:TSInsertTabletsReq req);
82. // test the latency of innsert record,caution:no data will be inserted, only for test latency
83. TSStatus testInsertRecord(1:TSInsertRecordReq req);
85. // test the latency of innsert record in string format,caution:no data will be inserted, only for test latency
86. TSStatus testInsertStringRecord(1:TSInsertStringRecordReq req);
88. // test the latency of innsert records,caution:no data will be inserted, only for test latency
89. TSStatus testInsertRecords(1:TSInsertRecordsReq req);
91. // test the latency of innsert records of one device,caution:no data will be inserted, only for test latency
92. TSStatus testInsertRecordsOfOneDevice(1:TSInsertRecordsOfOneDeviceReq req);
94. // test the latency of innsert records in string formate,caution:no data will be inserted, only for test latency
95. TSStatus testInsertStringRecords(1:TSInsertStringRecordsReq req);
97. // delete data
98. TSStatus deleteData(1:TSDeleteDataReq req);
100. // execute raw data query
101. TSExecuteStatementResp executeRawDataQuery(1:TSRawDataQueryReq req);
103. // request a statement id from server
104. i64 requestStatementId(1:i64 sessionId);
