-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
73 lines (59 loc) · 2.18 KB
/
Copy pathtest.js
File metadata and controls
73 lines (59 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const { CQLSession } = require('.');
const SSL_DIR = '/home/mhmd/Downloads/cassandra-with-ssl/ssl';
async function main() {
console.log('Testing connection to localhost:9042 with SSL...\n');
const sslOptions = {
host: '127.0.0.1',
port: 9042,
username: 'cassandra',
password: 'cassandra',
sslCaFile: `${SSL_DIR}/ca.pem`,
sslCertfile: `${SSL_DIR}/server.crt.pem`,
sslKeyfile: `${SSL_DIR}/server.key.pem`,
sslValidate: false,
};
// Test connection first
const testResult = await CQLSession.testConnection(sslOptions);
console.log('Test connection result:', JSON.stringify(testResult, null, 2));
if (!testResult.success) {
console.error('\nConnection test failed:', testResult.error);
process.exit(1);
}
console.log('\nCluster info:');
console.log(' Cassandra version:', testResult.data.build);
console.log(' CQL version:', testResult.data.cql);
console.log(' Datacenter:', testResult.data.datacenter);
// Now establish a session
console.log('\nConnecting session...');
const connectResult = await CQLSession.connect(sslOptions);
if (!connectResult.success) {
console.error('Session connect failed:', connectResult.error);
process.exit(1);
}
const session = connectResult.data;
console.log('Connected! Cassandra', session.cassandraVersion);
try {
// Get session info
const info = await session.getInfo();
console.log('\nSession info:', JSON.stringify(info.data, null, 2));
// Run a simple query
const result = await session.execute('SELECT cluster_name, release_version FROM system.local');
if (result.success && result.data.rows) {
console.log('\nQuery result:');
console.log(' Columns:', result.data.columns);
console.log(' Rows:', result.data.rows);
}
// List keyspaces
const ksResult = await session.execute('SELECT keyspace_name FROM system_schema.keyspaces');
if (ksResult.success && ksResult.data.rows) {
console.log('\nKeyspaces:', ksResult.data.rows.map(r => r.keyspace_name).join(', '));
}
} finally {
await session.close();
console.log('\nSession closed.');
}
}
main().catch(err => {
console.error('Error:', err);
process.exit(1);
});