snippets_js
Integration
New integration from credential
const cassandraClient = yepcode.integration.cassandra("credential-slug");
New integration from plain authentication data
const cassandra = require('cassandra-driver');
const cassandraClient = new cassandra.Client({
contactPoints: ['h1', 'h2'],
localDataCenter: 'datacenter1',
keyspace: 'ks1'
});
New integration with authentication data
const cassandra = require('cassandra-driver');
const authProvider = new cassandra.auth.PlainTextAuthProvider(
"username",
"password"
);
const cassandraClient = new cassandra.Client({
contactPoints,
authProvider,
localDataCenter,
keyspace
});
Executes a Query
Executes a query
const query = 'SELECT name, email FROM users WHERE key = ?';
cassandraClient.execute(query, [ 'someone' ])
.then(result => console.log('User with email %s', result.rows[0].email));
Prepared Statements
Prepared statements
// Use query markers (?) and parameters
const query = 'UPDATE users SET birth = ? WHERE key=?';
const params = [ new Date(1942, 10, 1), 'jimi-hendrix' ];
// Set the prepare flag in the query options
await cassandraClient.execute(query, params, { prepare: true });
Execute Concurrent Executions
Execute concurrent executions
await cassandraClient.execute(`CREATE KEYSPACE IF NOT EXISTS examples
WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1' }`);
await cassandraClient.execute(`USE examples`);
await cassandraClient.execute(`CREATE TABLE IF NOT EXISTS tbl_sample_kv (id uuid, value text, PRIMARY KEY (id))`);
// The maximum amount of async executions that are going to be launched in parallel
// at any given time
const concurrencyLevel = 32;
// Use an Array with 10000 different values
const values = Array.from(new Array(10000).keys()).map(x => [ Uuid.random(), x.toString() ]);
const query = 'INSERT INTO tbl_sample_kv (id, value) VALUES (?, ?)';
await executeConcurrent(client, query, values);
Paging
Paging
const queries = [
{
query: 'UPDATE user_profiles SET email=? WHERE key=?',
params: [ emailAddress, 'hendrix' ]
}, {
query: 'INSERT INTO user_track (key, text, date) VALUES (?, ?, ?)',
params: [ 'hendrix', 'Changed email', new Date() ]
}
];
await cassandraClient.batch(queries, { prepare: true });
Mapper
Mapper
const cassandra = require('cassandra-driver');
const Mapper = cassandra.mapping.Mapper;
const mapper = new Mapper(cassandraClient, {
models: { 'Video': { tables: ['videos'] } }
});
// Contains all the logic to retrieve and save objects from and to the database
const videoMapper = mapper.forModel('Video');