Baidu AI Cloud
中国站

百度智能云

Time-Spatial Database

Management Interface

Create a TsdbAdminClient

var TsdbAdminClient = require('@baiducloud/sdk').TsdbAdminClient; 
 
const config = {
    endpoint: <Endpoint>,            // Domain name address of the management interface with the format such as tsdb.{region}.baidubce.com. Note: It is different from the endpoint used when creating a TsdbClient.
    credentials: {
         ak: <AccessKeyID>,          // user's Access Key ID 
         sk: <SecretAccessKey>       // user's Secret Access Key
    }
};
 
// initialize a TsdbAdminClient
const client = new TsdbAdminClient(config);

Get a Time Series Database Instance

Basic Process

  1. Create a TsdbAdminClient.
  2. Run the createDatabase () method, you need to set up various information of the database, referring to the API design documentation for details.

The code example is as follows:

// set the instance parameters
var databaseName = "test";                   // instance name
var clientToken = UUID.v4();                  // ClientToken, used to guarantee the idempotence. Same clientToken is used when sending the create requests.
var description = 'This is just a test for TSDB.';     // instance description, optional
var ingestDataPointsMonthly = 1;                       // write quota, unit: millions of points/month
var storeBytesQuota = 1;                               // storage space capacity quota unit: GB
var purchaseLength = 1;                                // purchase duration, unit: month
var couponName = <your-coupon-name>;                   // coupon number, optional
 
// create and return results
client.createDatabase(clientToken, databaseName, ingestDataPointsMonthly, purchaseLength, description,storeBytesQuota)
   .then(response => console.log(response.body))       // created successfully
   .catch(error => console.error(error));              // failed to create and return the error type
    

Fields of the return value, please refer to API Documentation.

Delete a Time Series Database Instance

Basic Process

  1. Create a TsdbAdminClient.
  2. Run the deleteDatabase () method, you need to provide the databaseId of the database to be deleted.

The code example is as follows:

// delete the instance ID
var databaseId = 'tsdb-dvb9we5yfkcc';
 
// delete the instance and return results
client.deleteDatabase(databaseId)
    .then(response => console.log(response))         // deleted successfully
    .catch(error => console.error(error));                   // failed to delete and return the error type
    

Note: Only Instance of deleting an expired time series database is permitted. Otherwise, an error occurs.

The running result is as follows:

//  failed to delete (typically because the database is not expired)
{ 
  status_code: 400,
  message: 'Can not delete unexpired database',
  code: 'DeleteUnexpiredDatabaseFailed',
  request_id: '2a92ae76-87a2-432f-92a9-a426d2b447b6' 
 }
// deleted successfully (the database is expired)
  body: {}

Get a Time Series Database Instance

Basic Process

  1. Create a TsdbAdminClient.
  2. Run the getDatabaseInfo () method, you need to provide the databaseId of the database to be obtained.

The code example is as follows:

// get the instance ID
var databaseId = 'tsdb-dvb9we5yfkcc';
  
// get the instance and return the instance information
client.getDatabaseInfo(databaseId)
    .then(response => console.log(response.body))            // got successfully and return the information list
    .catch(error => console.error(error));                   // failed to get and return the error type

The running code is as follows:

//  similar results return from the termination
{
    databaseId: 'tsdb-tfu33g88m658',
    databaseName: 'testgeturl',
    description: '',
    endpoint: 'testgeturl.tsdb.iot.gz.baidubce.com',
    quota: {
        ingestDataPointsMonthly: 1
    },
    status: 'Active',
    autoExport: false,
    createTime: '2017-10-11T08:51:09Z',
    expiredTime: '2017-11-11T08:51:09Z'
}

Get a Time Series Database Instance List

Basic Process

  1. Create a TsdbAdminClient.
  2. Run the listDatabase () method.

The code example is as follows:

// get and return results
client.listDatabase()
    .then(response => console.log(response.body))            // got successfully and return the list containing each database information
    .catch(error => console.error(error));                   // failed to get and return the error type

The running result is as follows:

//  similar results return from the termination and print all databases
[
    {
        "databaseId": "tsdb-dvb9we5yfkcc",
        "databaseName": "viztest",
        "description": "Ownedby  IoT Visualization, Don\'tremove",
        "endpoint": "viztest.tsdb.iot.gz.baidubce.com",
        "quota": {
            "ingestDataPointsMonthly": 100
        },
        "status": "Active",
        "autoExport": "false",
        "createTime": "2017-06-14T07:41:46Z",
        "expiredTime": "2018-06-14T07:41:47Z"
    },
    {
        "databaseId": "tsdb-n88psnkq965c",
        "databaseName": "vizyingyan",
        "description": " testing data of IoT Visualization map",
        "endpoint": "vizyingyan.tsdb.iot.gz.baidubce.com",
        "quota": {
            "ingestDataPointsMonthly": 10
        },
        "status": "Active",
        "autoExport": "false",
        "createTime": "2017-06-20T04:01:03Z",
        "expiredTime": "2018-06-20T04:01:03Z"
    }
]
Previous
Gzip Compression Instruction of Writing Data Points
Next
Error Code