GithubHelp home page GithubHelp logo

athiwatp / cassandrom Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kiril-me/cassandrom

0.0 1.0 0.0 373 KB

Cassandra object modeling tool for Node.Js like mongoose

License: Apache License 2.0

JavaScript 100.00%

cassandrom's Introduction

Cassandrom

Cassandrom is a Cassandra object modeling tool for Node JS (like mongoose).

Installation

Install node.js and cassandra

$ npm install cassandrom

Connecting to Cassandra

To use cassandrom first create connection.

var cassandrom = require('cassandrom');

cassandrom.createConnection({ contactPoints: [
  'localhost'
  // , 'another-host',
  ], keyspace: 'keyspace'});

Defining a Schema

var schema = new cassandrom.Schema({
  userId:   { type: cassandrom.UUIDType, required: true, trim: 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 }

}, true);

Get Model and Start work

var User = cassandrom.model("User", schema);

Create and save Model

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.

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);
});

Add New Methods

schema.statics.findByUserame = function(name, callback) {
  this.findOne({ username: name }, callback);
};

schema.statics.findById = function(id, callback) {
  this.findOne({ userId: id }, callback);
};

Cassandra Driver access

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.

cassandrom's People

Contributors

kiril-me avatar

Watchers

athiwatp avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.