Cassandrom is a Cassandra object modeling tool for Node JS (like mongoose).
$ npm install cassandrom
To use cassandrom first create connection.
var cassandrom = require('cassandrom');
cassandrom.createConnection({ contactPoints: [
'localhost'
// , 'another-host',
], localDataCenter: 'datacenter1', keyspace: 'keyspace'});
var schema = new cassandrom.Schema({
userId: { type: cassandrom.UUIDType, required: true, default: cassandrom.uuid },
fullName: { type: String, required: true, trim: true },
username: { type: String, required: true, unique: true, trim: true },
email: { type: String, required: true, unique: true, trim: true },
password: { type: String, required: true },
date: { type: Date, default: Date.now, required: true }
}, ['userId']);
var User = cassandrom.model("User", schema);
User.create({
fullName: 'John Doe',
username: 'john',
email: '[email protected]',
password: 'doedoe'
}, function (error, user) {
if(error) {
console.log('Error during user save: ' + error);
} else {
console.log('User saved ' + user.userId + ' date ' + user.date);
}
});
Find all records match the certain field.
User.find({ username: name }, function(error, results) {
console.log('Find ' + results.length + ' users');
});
Find only one record.
User.findOne({ username: name }, function(error, user) {
console.log('Find found ' + user);
});
schema.statics.findByUserame = function(name, callback) {
this.findOne({ username: name }, callback);
};
schema.statics.findById = function(id, callback) {
this.findOne({ userId: id }, callback);
};
User.findOne({ username: name })
.then(function(user)) {
}
.catch(function(error) {
});
const user = await aUser.findOne({ username: name });
DataStax nodejs-driver for Apache Cassandra were used.
Kiril Menshikov - https://twitter.com/kiril
Code released under the Apache 2.0 license.