cassandra-repository
v0.0.0
Published
Generic IRepository implementation for Cassandra
Downloads
6
Maintainers
Readme
Cassandra Repository
Installation
$ npm install --save cassandra-repository
Usage
const CassandraRepository = require('cassandra-repository');
class CatRepository extends CassandraRepository {
constructor(cassandra, modelName) {
super(cassandra, modelName);
}
}
// or if you dont need custom functionality
const repo = new CassandraRepository(cassandra, modelName);
Getting Started
'use strict';
const Cassandra = require('express-cassandra');
const CassandraRepository = require('cassandra-repository');
const cassandra = Cassandra.createClient({
clientOptions: {
contactPoints: ['127.0.0.1'],
protocolOptions: { port: 9042 },
keyspace: 'mykeyspace',
queryOptions: { consistency: Cassandra.consistencies.one }
},
ormOptions: {
defaultReplicationStrategy: {
class: 'SimpleStrategy',
replication_factor: 1
},
migration: 'safe',
createKeyspace: true
}
});
export const modelName = 'Cats';
// configure a schema
export const schema = {
fields: {
_id: 'text',
name: 'text'
},
key: ['_id']
};
let cassandraRepo;
// json object
const cat = { name : 'Fido' };
cassandra.connect(() => {
// register it to cassandra
cassandra.loadSchema(modelName, schema);
repo = new CassandraRepository(cassandra, modelName);
repo.add(cat, (err, data) => {
console.log(data);
repo.disconnect();
});
});
License
MIT © Ben Lugavere