Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kiril-me/cassandrom
Cassandra object modeling tool for Node.Js like mongoose
https://github.com/kiril-me/cassandrom
cassandra javascript mongoose nodejs orm
Last synced: about 2 months ago
JSON representation
Cassandra object modeling tool for Node.Js like mongoose
- Host: GitHub
- URL: https://github.com/kiril-me/cassandrom
- Owner: kiril-me
- License: apache-2.0
- Created: 2015-02-28T21:10:53.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2019-02-08T10:23:58.000Z (almost 6 years ago)
- Last Synced: 2024-10-23T08:55:42.443Z (3 months ago)
- Topics: cassandra, javascript, mongoose, nodejs, orm
- Language: JavaScript
- Homepage:
- Size: 455 KB
- Stars: 38
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Cassandrom
Cassandrom is a Cassandra object modeling tool for Node JS (like mongoose).
# Installation
Install [node.js](http://nodejs.org/) and [cassandra](http://cassandra.apache.org/download/)
```sh
$ npm install cassandrom
```# Connecting to Cassandra
To use cassandrom first create connection.```js
var cassandrom = require('cassandrom');cassandrom.createConnection({ contactPoints: [
'localhost'
// , 'another-host',
], localDataCenter: 'datacenter1', keyspace: 'keyspace'});```
# Defining a Schema
```js
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']);
```# Get Model and Start work
```js
var User = cassandrom.model("User", schema);
```# Create and save Model
```js
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);
}
});
```# Searching
Find all records match the certain field.
```js
User.find({ username: name }, function(error, results) {
console.log('Find ' + results.length + ' users');
});
```Find only one record.
```js
User.findOne({ username: name }, function(error, user) {
console.log('Find found ' + user);
});
```# Add New Methods
```js
schema.statics.findByUserame = function(name, callback) {
this.findOne({ username: name }, callback);
};schema.statics.findById = function(id, callback) {
this.findOne({ userId: id }, callback);
};
```# Promise
```js
User.findOne({ username: name })
.then(function(user)) {}
.catch(function(error) {});
```# ES6
```js
const user = await aUser.findOne({ username: name });
```# Cassandra Driver access
DataStax [nodejs-driver](https://github.com/datastax/nodejs-driver) for Apache Cassandra were used.# Creators
_Kiril Menshikov_ - https://twitter.com/kiril
# Copyright and license
Code released under the Apache 2.0 license.