Todos los productos
Search
Centro de documentos

Tablestore:Consulta de información de una tabla

Última actualización: Sep 03, 2026

Este tema describe cómo consultar la información de una tabla mediante el SDK de Tablestore para Node.js.

Requisitos previos

Se requiere un cliente inicializado. Para obtener más información, consulte Initialize a Tablestore client.

Descripción del método

describeTable: function describeTable(params, callback)

Descripción del parámetro params

tableName (obligatorio) string: El nombre de la tabla.

Código de ejemplo

A continuación se muestra un código de ejemplo que demuestra cómo consultar la información de la tabla test_table.

var params = {
    tableName: 'test_table'
};

client.describeTable(params, function (err, data) {
    if (err) {
        console.error('error:', err);
        return;
    }

    // Query the schema information of a table.
    var tableMeta = data.tableMeta;
    console.log('* Table name:', tableMeta.tableName);
    console.log('* Primary key information (primary key type 1:INTEGER,2:STRING,3:BINARY)');
    tableMeta.primaryKey.forEach(function (primaryKey) {
        console.log(primaryKey.name, ':', primaryKey.type);
    });
    console.log("* Predefined column information (predefined column type 1:INTEGER,2:DOUBLE,3:BOOLEAN,4:STRING)");
    tableMeta.definedColumn.forEach(function (definedColumn) {
        console.log(definedColumn.name, ':', definedColumn.type);
    });

    // Obtain table configuration information.
    var tableOptions = data.tableOptions;
    console.log("* Table configuration information");
    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);

    // Obtain table Stream information.
    var streamDetails = data.streamDetails
    console.log("* Whether to enable Stream:", streamDetails.enableStream);
    if (streamDetails.enableStream) {
        console.log("Stream expiration time:", streamDetails.expirationTime);
    }

    // Obtain reserved read/write throughput of the table.
    var reservedThroughputDetails = data.reservedThroughputDetails
    console.log("* Reserved read/write throughput");
    console.log("Reserved read throughput:", reservedThroughputDetails.capacityUnit.read);
    console.log("Reserved write throughput:", reservedThroughputDetails.capacityUnit.write);

    // Obtain secondary index information.
    data.indexMetas.forEach(function (indexMeta) {
        console.log("* Secondary index name:", indexMeta.name);
        console.log("Primary key columns:", indexMeta.primaryKey);
        console.log("Predefined columns:", indexMeta.definedColumn);
        console.log("Secondary index type:", indexMeta.indexType, "(0:IT_GLOBAL_INDEX,1:IT_LOCAL_INDEX)");
        console.log("Secondary index update mode:", indexMeta.indexUpdateMode, "(0:IUM_ASYNC_INDEX,1:IUM_SYNC_INDEX)");
    });
});