简体   繁体   English

Cassandra + nodejs:如何获得Keyspaces和表格?

[英]Cassandra+nodejs: how to get the Keyspaces and Tables?

I am trying to get the metadata, keyspaces, tables from a Cassandra Cluster. 我试图从Cassandra集群中获取元数据,密钥空间和表。 I am using the following node.js code: 我使用以下node.js代码:

var express = require('express');
var bodyParser = require('body-parser');
var cassandra = require('cassandra-driver');

var client = new cassandra.Client( { contactPoints : [ '127.0.0.1' ] } );
client.connect(function(err, result) {
    console.log('Connected To the Database.');
});

var app = express();
app.use(bodyParser.json());
app.set('json spaces', 2);

app.get('/metadata', function(req, res) {
    res.send(client.hosts.slice(0).map(function (node) {
        return { address : node.address, rack : node.rack, datacenter :     node.datacenter }
    }));
});



app.get('/metadata/keyspaces', function(req, res) {
    client.execute("DESCRIBE KEYSPACES;", function(err, result) {
        if (err) {
            res.status(404).send(err);
        } else {
            res.json(result);        }
    });
});

app.get('/metadata/tables', function(req, res) {
    client.execute("DESCRIBE TABLES", function(err, result) {
        if (err) {
            res.status(404).send({ msg : 'No Table found' });
        } else {
            res.json(result);        }
    });
});

var server = app.listen(3000, function() {
    console.log('Listening on port %d', server.address().port);
});

Problem is, when i run the above code, I do not get the existing keyspaces or tables from the database, Instead I get the following error: 问题是,当我运行上面的代码时,我没有从数据库中获取现有的键空间或表,而是出现以下错误:

{
  "name": "ResponseError",
  "message": "line 1:0 no viable alternative at input 'DESCRIBE'",
  "info": "Represents an error message from the server",
  "code": 8192,
  "query": "DESCRIBE KEYSPACES;"
}

How can I see the these informations? 我怎样才能看到这些信息? Thank you in advance for help. 提前感谢您的帮助。

UPDATE: 更新:

I just came to know, DESCRIBE is a cqlsh command, so How I can solve in my case? 我刚才知道,DESCRIBE是一个cqlsh命令,所以我怎么能在我的情况下解决?

DESCRIBE is a command only available on cqlsh tool. DESCRIBE是仅在cqlsh工具上可用的命令。

Try querying system tables as it is described here . 尝试查询系统表,因为它是描述在这里

List of keyspaces: 键空间列表:

SELECT keyspace_name FROM system.schema_keyspaces;

List of columnfamilies in keyspace: 密钥空间中的columnfamilies列表:

SELECT columnfamily_name FROM system.schema_columnfamilies WHERE keyspace_name = '<keyspace_name>';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM