Topik ini menjelaskan cara mengambil informasi tabel menggunakan Tablestore SDK untuk Node.js.
Prasyarat
Klien telah diinisialisasi. Untuk detail lebih lanjut, lihat Inisialisasi Klien Tablestore.
Deskripsi metode
describeTable: function describeTable(params, callback)Kode contoh
Berikut adalah contoh kode untuk mengambil informasi tabel test_table.
var params = {
tableName: 'test_table'
};
client.describeTable(params, function (err, data) {
if (err) {
console.error('error:', err);
return;
}
// Mengambil informasi skema tabel.
var tableMeta = data.tableMeta;
console.log('* Nama tabel:', tableMeta.tableName);
console.log('* Informasi kunci utama (tipe kunci utama 1:INTEGER,2:STRING,3:BINARY)');
tableMeta.primaryKey.forEach(function (primaryKey) {
console.log(primaryKey.name, ':', primaryKey.type);
});
console.log("* Informasi kolom yang telah ditentukan sebelumnya (tipe kolom yang telah ditentukan sebelumnya 1:INTEGER,2:DOUBLE,3:BOOLEAN,4:STRING)");
tableMeta.definedColumn.forEach(function (definedColumn) {
console.log(definedColumn.name, ':', definedColumn.type);
});
// Memperoleh informasi konfigurasi tabel.
var tableOptions = data.tableOptions;
console.log("* Informasi konfigurasi tabel");
console.log("Versi maksimum:", tableOptions.maxVersions);
console.log("Waktu kedaluwarsa:", tableOptions.timeToLive);
console.log("Offset versi maksimum:", tableOptions.deviationCellVersionInSec.toNumber());
console.log("Izinkan pembaruan:", tableOptions.allowUpdate);
// Memperoleh informasi Stream tabel.
var streamDetails = data.streamDetails
console.log("* Apakah Stream diaktifkan:", streamDetails.enableStream);
if (streamDetails.enableStream) {
console.log("Waktu kedaluwarsa Stream:", streamDetails.expirationTime);
}
// Memperoleh throughput baca/tulis yang dicadangkan untuk tabel.
var reservedThroughputDetails = data.reservedThroughputDetails
console.log("* Throughput baca/tulis yang dicadangkan");
console.log("Throughput baca yang dicadangkan:", reservedThroughputDetails.capacityUnit.read);
console.log("Throughput tulis yang dicadangkan:", reservedThroughputDetails.capacityUnit.write);
// Memperoleh informasi indeks sekunder.
data.indexMetas.forEach(function (indexMeta) {
console.log("* Nama indeks sekunder:", indexMeta.name);
console.log("Kolom kunci utama:", indexMeta.primaryKey);
console.log("Kolom yang telah ditentukan sebelumnya:", indexMeta.definedColumn);
console.log("Tipe indeks sekunder:", indexMeta.indexType, "(0:IT_GLOBAL_INDEX,1:IT_LOCAL_INDEX)");
console.log("Mode pembaruan indeks sekunder:", indexMeta.indexUpdateMode, "(0:IUM_ASYNC_INDEX,1:IUM_SYNC_INDEX)");
});
});