nest-cassandra
v0.0.5
Published
Cassandra utilities module for NestJs.
Downloads
6
Keywords
Readme
Description
Cassandra utilities module for NestJs.
Installation
$ npm install nest-cassandra
Usage
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
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
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.
Stay in touch
- Author - Kamil Myśliwiec
- Website - https://nestjs.com
- Twitter - @nestframework
License
Nest is MIT licensed.