# nest-cassandra

> Cassandra utilities module for NestJs.

Latest version **0.0.5** (published 2022-03-29) · ISC license · 0 weekly downloads

## Install

```sh
npm install nest-cassandra
pnpm add nest-cassandra
yarn add nest-cassandra
bun add nest-cassandra
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2022-03-29 |
| First published | 2022-03-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 145.8 KB |
| Known vulnerabilities | 0 (+3 in 2 direct dependencies) |
| Install scripts | no |
| Maintainers | gerardo15 |

## Links

- npm: https://www.npmjs.com/package/nest-cassandra
- npm.io page: https://npm.io/package/nest-cassandra

## Dependencies (7)

- [rxjs](https://npm.io/package/rxjs.md) ^7.2.0
- [rimraf](https://npm.io/package/rimraf.md) ^3.0.2
- [@nestjs/core](https://npm.io/package/@nestjs/core.md) ^8.0.0
- [@nestjs/common](https://npm.io/package/@nestjs/common.md) ^8.0.0
- [cassandra-driver](https://npm.io/package/cassandra-driver.md) ^4.6.3
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.13
- [@nestjs/platform-express](https://npm.io/package/@nestjs/platform-express.md) ^8.0.0

## Recent versions

- 0.0.5 (latest) — 2022-03-29
- 0.0.4 — 2022-03-29
- 0.0.3 — 2022-03-29
- 0.0.2 — 2022-03-28

## README

<p align="center">
  <a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo_text.svg" width="320" alt="Nest Logo" /></a>
</p>

[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
[circleci-url]: https://circleci.com/gh/nestjs/nest

  <p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
    <p align="center">
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
  <a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
    <a href="https://opencollective.com/nest#sponsor"  target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
  <a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
</p>
  <!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
  [![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->

## Description

Cassandra utilities module for NestJs.

## Installation

```bash
$ npm install nest-cassandra
```

## Usage

```js
import { CassandraModule } from 'nest-cassandra'
import { auth } from 'cassandra-driver'

@Module({
  imports: [
    CassandraModule.forRoot({
      keyspace: 'test',
      contactPoints: ['127.0.0.1:9042'],
      localDataCenter: 'datacenter1',
      authProvider: new auth.PlainTextAuthProvider('user', 'pass');
    })
  ],
  providers: [...]
})
export class AppModule {}
```

## Model

```js
import { CassandraModel } from 'nest-cassandra'
import { types } from 'cassandra-driver'

export class LookupByHash extends CassandraModel {
  @CassandraPartitioningKey()
  @CassandraColumn(types.dataTypes.blob)
  @CassandraTransforms({
    fromJSON: hexStringToBlob,
    fromCassandra: hexBlobToString,
  })
  hash: string;

  @CassandraClusteringKey()
  @CassandraColumn(types.dataTypes.blob)
  archive: string;

  @CassandraColumn(types.dataTypes.timestamp)
  timestamp: Date;
}

```

# Crud

```js
import { Injectable } from '@nestjs/common';
import { CassandraRepository } from 'nest-cassandra'

export class LookupByHashRepository extends CassandraRepository<LookupByHash> {
  tableName = 'lookup_by_hash';
  modelName = 'LookupByHash';
  model = new LookupByHash();
}

@Injectable()
export class LookupByHashService {
  constructor(
    private readonly boundWitnessesByHashRepository: LookupByHashRepository,
  ) {}

  findByHash(hash: string) {
    return this.boundWitnessesByHashRepository.findOne({ hash });
  }

  page({ limit, cursor, ...query }) {
    return this.boundWitnessesByArchiveRepository.page(query, {
      limit,
      cursor,
    });
  }
}

```

## Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).

## Stay in touch

- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com)
- Website - [https://nestjs.com](https://nestjs.com/)
- Twitter - [@nestframework](https://twitter.com/nestframework)

## License

Nest is [MIT licensed](LICENSE).

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