Skip to content

senecajs-labs/seneca-cassandra-store

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Seneca seneca-cassandra-store

[![npm version][npm-badge]][npm-url] [![Dependency Status][david-badge]][david-url] [![Gitter chat][gitter-badge]][gitter-url]

seneca-cassandra-store is a Cassandra database plugin for the Seneca MVP toolkit. It uses the Cassandra Client CQL driver.

Install

npm install seneca
npm install seneca-cassandra-store

Using seneca-cassandra-store

var seneca = require('seneca');
var store = require('cassandra-store');

var config = {}
var storeopts = {
  name: 'senecatest',
  host: '127.0.0.1',
  port: 9160
};

var Si = seneca(config)
Si.use(store, storeopts)

Si.ready(function() {
  var entity = seneca.make$('typename')
  entity.someproperty = "something"
  entity.anotherproperty = 100

  entity.save$( function(err,entity){ ... } )
  entity.load$( {id: ...}, function(err,entity){ ... } )
  entity.list$( {property: ...}, function(err,entity){ ... } )
  entity.remove$( {id: ...}, function(err,entity){ ... } )
})

Queries

The standard Seneca query format is supported:

  • entity.list$({field1:value1, field2:value2, ...}) implies pseudo-query field1==value1 AND field2==value2, ...
  • entity.list$({f1:v1,...},{limit$:10}) means only return 10 results
  • due to cassandra restrictions you cannot use sort$, skip$ and fields$. These are not available for this storage.

Native Driver

As with all seneca stores, you can access the native driver, in this case, the cassandra-client object using entity.native$(function(err,collection){...}).

Testing

For creating test environments please run following commands using cassandra-cli

connect localhost/9160;

create keyspace senecatest;

use senecatest;

create column family foo
with comparator = UTF8Type
  and key_validation_class = UTF8Type
  and column_metadata =
[
  {column_name : p1,validation_class : UTF8Type},
  {column_name : p2,validation_class : UTF8Type, index_type : 0, index_name : p2_idx}
];

create column family moon_bar
  with comparator = UTF8Type
  and key_validation_class = UTF8Type
  and column_metadata =
[
  {column_name : str, validation_class : UTF8Type},
  {column_name : int, validation_class : IntegerType},
  {column_name : dec, validation_class : UTF8Type},
  {column_name : bol, validation_class : BooleanType},
  {column_name : wen, validation_class : UTF8Type},
  {column_name : arr, validation_class : UTF8Type},
  {column_name : obj, validation_class : UTF8Type},
  {column_name : mark,validation_class : UTF8Type, index_type : 0, index_name : mark_idx},
  {column_name : seneca,validation_class : UTF8Type}
];

Acknowledgements

This project was sponsored by nearForm.

Contributing

The Senecajs org encourage open participation. If you feel you can help in any way, be it with documentation, examples, extra testing, or new features please get in touch.

License

Copyright Mircea Alexandru and other contributors 2016, Licensed under [MIT][]. [npm-badge]: https://badge.fury.io/js/seneca-cassandra-store.svg [npm-url]: https://badge.fury.io/js/seneca-cassandra-store [david-badge]: https://david-dm.org/senecajs-labs/seneca-cassandra-store.svg [david-url]: https://david-dm.org/senecajs-labs/seneca-cassandra-store [gitter-badge]: https://badges.gitter.im/senecajs/seneca.png [gitter-url]: https://gitter.im/senecajs/seneca [MIT]: ./LICENSE.txt

About

Cassandra db store plugin for seneca toolkit

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published