edit-icon download-icon

Table-level operations

Last Updated: Apr 08, 2018

The Table Store SDK provides the following APIs for operating tables: CreateTable, ListTable, DeleteTable, UpdateTable, and DescribeTable.

CreateTable

Creates a table based on the given table structure information.

When creating a table in Table Store, you must specify the table’s primary keys. A primary key contains one to four primary key columns. Each primary key column has a name and a type.

API

  1. /**
  2. * Create a table based on the given table structure information.
  3. */
  4. createTable(params, callback)

Note: After a table is created in Table Store, it takes several seconds to load the table. Do not perform any operations during this time.

Example

Create a table with two primary key columns and a reserved read/write throughput of (0,0).

  1. var client = require('./client');
  2. var params = {
  3. tableMeta: {
  4. tableName: 'sampleTable',
  5. primaryKey: [
  6. {
  7. name: 'gid',
  8. type: 'INTEGER'
  9. },
  10. {
  11. name: 'uid',
  12. type: 'INTEGER'
  13. }
  14. ]
  15. },
  16. reservedThroughput: {
  17. capacityUnit: {
  18. read: 0,
  19. write: 0
  20. }
  21. },
  22. tableOptions: {
  23. timeToLive: -1,// The data expiration time in seconds; –1 indicates that the data does not expire. To set the expiration time to one year, use 365 * 24 * 3600
  24. maxVersions: 1//The max number of versions to save. If it is set to 1, each column only saves the latest version
  25. }
  26. };
  27. client.createTable(params, function (err, data) {
  28. if (err) {
  29. console.log('error:', err);
  30. return;
  31. }
  32. console.log('success:', data);
  33. });

Note: Obtain the full sample codes at createTable@GitHub.

ListTable

Obtains the names of all tables under the current instance.

API

  1. /**
  2. * Obtain the names of all tables under the current instance.
  3. */
  4. listTable(params, callback)

Example

Obtain the names of all tables under an instance.

  1. var client = require('./client');
  2. client.listTable({}, function (err, data) {
  3. if (err) {
  4. console.log('error:', err);
  5. return;
  6. }
  7. console.log('success:', data);
  8. });

Note: Obtain the full sample codes at listTable@GitHub.

UpdateTable

Updates maxVersions and the reserved read or write throughput value of the specified table.

API

  1. /**
  2. * Update the reserved read or write throughput value of the specified table.
  3. */
  4. updateTable(params, callback)

Example

Set maxVersions of a table to 5.

  1. var client = require('./client');
  2. var params = {
  3. tableName: 'sampleTable',
  4. tableOptions: {
  5. maxVersions: 5,
  6. }
  7. };
  8. client.updateTable(params, function (err, data) {
  9. if (err) {
  10. console.log('error:', err);
  11. return;
  12. }
  13. console.log('success:', data);
  14. });

Note: Obtain the full sample codes at updateTable@GitHub.

DescribeTable

Queries the structure information and the reserved read/write throughput value of the specified table.

API

  1. /**
  2. * Query the structure information and the reserved read/write throughput value of the specified table.
  3. */
  4. describeTable(params, callback)

Example

  1. var client = require('./client');
  2. var params = {
  3. tableName: 'sampleTable'
  4. };
  5. client.describeTable(params, function (err, data) {
  6. if (err) {
  7. console.log('error:', err);
  8. return;
  9. }
  10. console.log('success:', data);
  11. });

Note: Obtain the full sample codes at describeTable@GitHub.

DeleteTable

Deletes the specified table under an instance.

API

  1. /**
  2. * Delete the specified table under an instance.
  3. */
  4. deleteTable(params, callback)

Example

Delete a table.

  1. var client = require('./client');
  2. var params = {
  3. tableName: 'sampleTable'
  4. };
  5. client.deleteTable(params, function (err, data) {
  6. if (err) {
  7. console.log('error:', err);
  8. return;
  9. }
  10. console.log('success:', data);
  11. });

Note: Obtain the full sample codes at deleteTable@GitHub.

Thank you! We've received your feedback.