このトピックでは、Node.js 用 Tablestore SDK を使用してテーブルの情報をクエリする方法について説明します。
前提条件
クライアントが初期化されていること。 詳細については、「Tablestore クライアントを初期化する」をご参照ください。
メソッドの説明
describeTable: function describeTable(params, callback)サンプルコード
次のサンプルコードは、test_table テーブルの情報をクエリする方法を示しています。
var params = {
tableName: 'test_table'
};
client.describeTable(params, function (err, data) {
if (err) {
console.error('error:', err);
return;
}
// テーブルのスキーマ情報をクエリします。
var tableMeta = data.tableMeta;
console.log('* Table name:', tableMeta.tableName);
console.log('* プライマリキー情報 (プライマリキータイプ 1:INTEGER,2:STRING,3:BINARY)');
tableMeta.primaryKey.forEach(function (primaryKey) {
console.log(primaryKey.name, ':', primaryKey.type);
});
console.log("* 事前定義された列情報 (事前定義された列タイプ 1:INTEGER,2:DOUBLE,3:BOOLEAN,4:STRING)");
tableMeta.definedColumn.forEach(function (definedColumn) {
console.log(definedColumn.name, ':', definedColumn.type);
});
// テーブル構成情報を取得します。
var tableOptions = data.tableOptions;
console.log("* テーブル構成情報");
console.log("Max versions:", tableOptions.maxVersions);
console.log("Time to live:", tableOptions.timeToLive);
console.log("Max version offset:", tableOptions.deviationCellVersionInSec.toNumber());
console.log("Allow update:", tableOptions.allowUpdate);
// テーブル Stream 情報を取得します。
var streamDetails = data.streamDetails
console.log("* Stream を有効にするかどうか:", streamDetails.enableStream);
if (streamDetails.enableStream) {
console.log("Stream の有効期限:", streamDetails.expirationTime);
}
// テーブルの予約済み読み取り/書き込みスループットを取得します。
var reservedThroughputDetails = data.reservedThroughputDetails
console.log("* 予約済み読み取り/書き込みスループット");
console.log("Reserved read throughput:", reservedThroughputDetails.capacityUnit.read);
console.log("Reserved write throughput:", reservedThroughputDetails.capacityUnit.write);
// セカンダリインデックス情報を取得します。
data.indexMetas.forEach(function (indexMeta) {
console.log("* セカンダリインデックス名:", indexMeta.name);
console.log("プライマリキー列:", indexMeta.primaryKey);
console.log("事前定義された列:", indexMeta.definedColumn);
console.log("セカンダリインデックスタイプ:", indexMeta.indexType, "(0:IT_GLOBAL_INDEX,1:IT_LOCAL_INDEX)");
console.log("セカンダリインデックス更新モード:", indexMeta.indexUpdateMode, "(0:IUM_ASYNC_INDEX,1:IUM_SYNC_INDEX)");
});
});