# cassandrom

> Cassandra JavaScript ORM

Latest version **0.0.4** (published 2019-02-08) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install cassandrom
pnpm add cassandrom
yarn add cassandrom
bun add cassandrom
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2019-02-08 |
| First published | 2015-02-28 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 10 |
| Unpacked size | 316.1 KB |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 39 |
| Author | Kirils Mensikovs |
| Maintainers | kiril |
| Keywords | cassandrom, cassandra, nodejs |

## Links

- npm: https://www.npmjs.com/package/cassandrom
- Repository: https://github.com/kiril-me/cassandrom
- Issues: https://github.com/kiril-me/cassandrom/issues
- npm.io page: https://npm.io/package/cassandrom

## Dependencies (10)

- [uuid](https://npm.io/package/uuid.md) ^3.3.2
- [async](https://npm.io/package/async.md) ^2.6.1
- [mpath](https://npm.io/package/mpath.md) ^0.5.1
- [kareem](https://npm.io/package/kareem.md) ^2.3.0
- [mquery](https://npm.io/package/mquery.md) ^3.2.0
- [sliced](https://npm.io/package/sliced.md) ^1.0.1
- [bluebird](https://npm.io/package/bluebird.md) ^3.5.3
- [hooks-fixed](https://npm.io/package/hooks-fixed.md) ^2.0.2
- [power-assert](https://npm.io/package/power-assert.md) ^1.6.1
- [cassandra-driver](https://npm.io/package/cassandra-driver.md) ^4.0.0

## Recent versions

- 0.0.4 (latest) — 2019-02-08
- 0.0.3 — 2018-03-31
- 0.0.25 — 2017-10-08
- 0.0.24 — 2017-10-02
- 0.0.23 — 2017-10-01
- 0.0.22 — 2017-10-01
- 0.0.21 — 2017-07-16
- 0.0.20 — 2017-06-22
- 0.0.19 — 2017-06-21
- 0.0.18 — 2017-06-21
- 0.0.17 — 2017-01-23
- 0.0.16 — 2016-01-20
- 0.0.15 — 2016-01-18
- 0.0.14 — 2015-08-01
- 0.0.13 — 2015-08-01
- … 3 more at https://npm.io/package/cassandrom/versions

## 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: 'john@doe.com',
  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.

---
_Source: https://npm.io/package/cassandrom · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
