{"id":14978691,"url":"https://github.com/ifaim/nestjs-express-cassandra","last_synced_at":"2025-10-28T11:31:56.512Z","repository":{"id":33152544,"uuid":"148752834","full_name":"ifaim/nestjs-express-cassandra","owner":"ifaim","description":"A express-cassandra module for Nest framework","archived":false,"fork":false,"pushed_at":"2023-04-27T12:58:13.000Z","size":866,"stargazers_count":54,"open_issues_count":51,"forks_count":27,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-08T22:43:20.653Z","etag":null,"topics":["cassandra","express-cassandra","nestjs","node-module","nodejs","orm"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ifaim.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-14T07:34:28.000Z","updated_at":"2024-09-05T00:12:47.000Z","dependencies_parsed_at":"2024-06-19T11:14:19.914Z","dependency_job_id":"d7af11fc-7b3f-428b-873c-6862250d84c5","html_url":"https://github.com/ifaim/nestjs-express-cassandra","commit_stats":{"total_commits":37,"total_committers":1,"mean_commits":37.0,"dds":0.0,"last_synced_commit":"75d3cccd99b99cf4c659bcf70060c4bbaa8f08ad"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ifaim%2Fnestjs-express-cassandra","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ifaim%2Fnestjs-express-cassandra/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ifaim%2Fnestjs-express-cassandra/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ifaim%2Fnestjs-express-cassandra/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ifaim","download_url":"https://codeload.github.com/ifaim/nestjs-express-cassandra/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219859638,"owners_count":16556035,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cassandra","express-cassandra","nestjs","node-module","nodejs","orm"],"created_at":"2024-09-24T13:58:12.159Z","updated_at":"2025-10-28T11:31:51.180Z","avatar_url":"https://github.com/ifaim.png","language":"TypeScript","funding_links":["https://opencollective.com/nest","https://paypal.me/kamilmysliwiec"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"http://nestjs.com/\" target=\"blank\"\u003e\u003cimg src=\"https://nestjs.com/img/logo_text.svg\" width=\"320\" alt=\"Nest Logo\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n[travis-image]: https://api.travis-ci.org/nestjs/nest.svg?branch=master\n[travis-url]: https://travis-ci.org/nestjs/nest\n[linux-image]: https://img.shields.io/travis/nestjs/nest/master.svg?label=linux\n[linux-url]: https://travis-ci.org/nestjs/nest\n\n  \u003cp align=\"center\"\u003eA progressive \u003ca href=\"http://nodejs.org\" target=\"blank\"\u003eNode.js\u003c/a\u003e framework for building efficient and scalable server-side applications, heavily inspired by \u003ca href=\"https://angular.io\" target=\"blank\"\u003eAngular\u003c/a\u003e.\u003c/p\u003e\n    \u003cp align=\"center\"\u003e\n\u003ca href=\"https://www.npmjs.com/~nestjscore\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/@nestjs/core.svg\" alt=\"NPM Version\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/~nestjscore\"\u003e\u003cimg src=\"https://img.shields.io/npm/l/@nestjs/core.svg\" alt=\"Package License\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/~nestjscore\"\u003e\u003cimg src=\"https://img.shields.io/npm/dm/@nestjs/core.svg\" alt=\"NPM Downloads\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://travis-ci.org/nestjs/nest\"\u003e\u003cimg src=\"https://api.travis-ci.org/nestjs/nest.svg?branch=master\" alt=\"Travis\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://travis-ci.org/nestjs/nest\"\u003e\u003cimg src=\"https://img.shields.io/travis/nestjs/nest/master.svg?label=linux\" alt=\"Linux\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://coveralls.io/github/nestjs/nest?branch=master\"\u003e\u003cimg src=\"https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#5\" alt=\"Coverage\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://gitter.im/nestjs/nestjs?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=body_badge\"\u003e\u003cimg src=\"https://badges.gitter.im/nestjs/nestjs.svg\" alt=\"Gitter\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/nest#backer\"\u003e\u003cimg src=\"https://opencollective.com/nest/backers/badge.svg\" alt=\"Backers on Open Collective\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/nest#sponsor\"\u003e\u003cimg src=\"https://opencollective.com/nest/sponsors/badge.svg\" alt=\"Sponsors on Open Collective\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://paypal.me/kamilmysliwiec\"\u003e\u003cimg src=\"https://img.shields.io/badge/Donate-PayPal-dc3d53.svg\"/\u003e\u003c/a\u003e\n  \u003ca href=\"https://twitter.com/nestframework\"\u003e\u003cimg src=\"https://img.shields.io/twitter/follow/nestframework.svg?style=social\u0026label=Follow\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n  \u003c!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)\n  [![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)--\u003e\n\n## Description\n\nExpress Cassandra utilities module for [NestJS](https://github.com/nestjs/nest) based on the [express-cassandra](https://github.com/masumsoft/express-cassandra) package.\n\n## Installation\n\n```bash\n$ npm i --save @iaminfinity/express-cassandra\n```\n## Usage\n\nImport `ExpressCassandraModule`:\n\n```typescript\n@Module({\n  imports: [\n    ExpressCassandraModule.forRoot({...})\n  ],\n  providers: [...]\n})\nexport class AppModule {}\n```\n\n## Async options\n\nQuite often you might want to asynchronously pass your module options instead of passing them beforehand. In such case, use registerAsync() method, that provides a couple of various ways to deal with async data.\n\n**1. Use factory**\n\n```typescript\nExpressCassandraModule.forRootAsync({\n  useFactory: () =\u003e ({...}),\n})\n```\n\nObviously, our factory behaves like every other one (might be `async` and is able to inject dependencies through `inject`).\n\n```typescript\nExpressCassandraModule.forRootAsync({\n  imports: [ConfigModule],\n  useFactory: (configService: ConfigService) =\u003e configService.getDbConfig(),\n  inject: [ConfigService],\n})\n```\n\n**2. Use class**\n\n```typescript\nExpressCassandraModule.forRootAsync({\n  useClass: ConfigService,\n})\n```\n\nAbove construction will instantiate `ConfigService` inside `ExpressCassandraModule` and will leverage it to create options object.\n\n```typescript\nclass ConfigService implements ExpressCassandraOptionsFactory {\n  createExpressCassandraOptions(): ExpressCassandraModuleOptions {\n    return {...};\n  }\n}\n```\n\n**3. Use existing**\n\n```typescript\nExpressCassandraModule.forRootAsync({\n  imports: [ConfigModule],\n  useExisting: ConfigService\n})\n```\n\nIt works the same as `useClass` with one critical difference - `ExpressCassandraModule` will lookup imported modules to reuse already created ConfigService, instead of instantiating it on its own.\n\n## ORM Options\n\n```typescript\nimport { Entity, Column } from '@iaminfinity/express-cassandra';\n\n@Entity({\n  table_name: 'photo',\n  key: ['id'],\n})\nexport class PhotoEntity {\n  @Column({\n    type: 'uuid',\n    default: { $db_function: 'uuid()' },\n  })\n  id: any;\n\n  @Column({\n    type: 'text',\n  })\n  name: string;\n}\n```\n\nLet's have a look at the `PhotoModule`\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { ExpressCassandraModule } from '@iaminfinity/express-cassandra';\nimport { PhotoService } from './photo.service';\nimport { PhotoController } from './photo.controller';\nimport { PhotoEntity } from './photo.entity';\n\n@Module({\n  imports: [ExpressCassandraModule.forFeature([PhotoEntity])],\n  providers: [PhotoService],\n  controllers: [PhotoController],\n})\nexport class PhotoModule {}\n```\n\nThis module uses `forFeature()` method to define which entities shall be registered in the current scope. Thanks to that we can inject the `PhotoEntity` to the `PhotoService` using the `@InjectModel()` decorator:\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { InjectModel, BaseModel } from '@iaminfinity/express-cassandra';\nimport { PhotoEntity } from './photo.entity';\n\n@Injectable()\nexport class PersonService {\n  constructor(\n    @InjectModel(PhotoEntity)\n    private readonly photoEntity: BaseModel\u003cPhotoEntity\u003e\n  ) {}\n\n  getByName(name: string): Promise\u003cPhotoEntity\u003e {\n    return this.photoEntity.findOneAsync({ name: name }, { raw: true });\n  }\n}\n```\n\n**Using Column Decorators:**\nTo auto-generate uuid/timeuuid column, you need to decorate an entity's properties you want to make into a auto-generated \nuuid/timeuuid column with a `@GeneratedUUidColumn` decorator.\n\n```typescript\nimport { Entity, Column, GeneratedUUidColumn } from '@iaminfinity/express-cassandra';\n\n@Entity({\n  table_name: 'photo',\n  key: ['id'],\n})\nexport class PhotoEntity {\n  @GeneratedUUidColumn()\n  id: any;\n\n  @GeneratedUUidColumn('timeuuid')\n  time_id: any;\n\n  @Column({\n    type: 'text',\n  })\n  name: string;\n}\n```\nTo auto-generate createdDate/updatedDate column, you need to decorate an entity's properties you want to make into a auto-generated \ncreatedDate/updatedDate column with a `@CreateDateColumn` or `@UpdateDateColumn` decorator.\n\nTo index a column, you need to decorate an entity's properties you want to index with a `@IndexColumn` decorator.\n\nTo auto-generate version column, you need to decorate an entity's properties you want to make into a auto-generated \nversion column with a `@VersionColumn` decorator.\n\n```typescript\nimport { \n  Entity,\n  Column,\n  GeneratedUUidColumn,\n  CreateDateColumn,\n  UpdateDateColumn,\n  IndexColumn,\n  VersionColumn,\n} from '@iaminfinity/express-cassandra';\n\n@Entity({\n  table_name: 'photo',\n  key: ['id'],\n})\nexport class PhotoEntity {\n  @GeneratedUUidColumn()\n  id: any;\n\n  @GeneratedUUidColumn('timeuuid')\n  time_id: any;\n\n  @Column({\n    type: 'text',\n  })\n  @IndexColumn()\n  name: string;\n\n  @CreateDateColumn()\n  created_at: Date;\n\n  @UpdateDateColumn()\n  updated_at: Date;\n\n  @VersionColumn()\n  __v1: any;\n}\n```\n\n**Using Hook Function Decorators:**\nAn entity of express-cassandra support multiple hook function. For more details [see](https://express-cassandra.readthedocs.io/en/stable/management/#hook-functions).\n\nTo create hook function in an entity use `@BeforeSave`, `@AfterSave`, `@BeforeUpdate`, `@AfterUpdate`, `@BeforeDelete`, `@AfterDelete` decorators.\n\n```typescript\nimport { \n  Entity,\n  Column,\n  GeneratedUUidColumn,\n  BeforeSave,\n  AfterSave,\n  BeforeUpdate,\n  AfterUpdate,\n  BeforeDelete,\n  AfterDelete,\n} from '@iaminfinity/express-cassandra';\n\n@Entity({\n  table_name: 'photo',\n  key: ['id'],\n})\nexport class PhotoEntity {\n  @GeneratedUUidColumn()\n  id: any;\n\n  @GeneratedUUidColumn('timeuuid')\n  time_id: any;\n\n  @BeforeSave()\n  beforeSave(instance: this, options: any) {}\n\n  @AfterSave()\n  afterSave(instance: this, options: any) {}\n\n  @BeforeUpdate()\n  beforeUpdate(query: any, updateValues: any, options: any) {}\n\n  @AfterUpdate()\n  afterUpdate(query: any, updateValues: any, options: any) {}\n\n  @BeforeDelete()\n  beforeDelete(query: any, options: any) {}\n\n  @AfterDelete()\n  afterDelete(query: any, options: any) {}\n}\n```\n\n## Using Repository\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { ExpressCassandraModule } from '@iaminfinity/express-cassandra';\nimport { PhotoService } from './photo.service';\nimport { PhotoController } from './photo.controller';\nimport { PhotoEntity } from './photo.entity';\n\n@Module({\n  imports: [ExpressCassandraModule.forFeature([PhotoEntity])],\n  providers: [PhotoService],\n  controllers: [PhotoController],\n})\nexport class PhotoModule {}\n```\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { InjectRepository, Repository } from '@iaminfinity/express-cassandra';\nimport { PhotoEntity } from './photo.entity';\nimport { Observable } from 'rxjs';\n\n@Injectable()\nexport class PersonService {\n  constructor(\n    @InjectRepository(PhotoEntity)\n    private readonly photoRepository: Repository\u003cPhotoEntity\u003e,\n  ) {}\n\n  getById(id: id): Observable\u003cPhotoEntity\u003e {\n    return this.photoRepository.findOne({id});\n  }\n}\n```\n\n## Using Custom Repository\n\nLet's create a repository:\n\n```typescript\nimport { Repository, EntityRepository } from '@iaminfinity/express-cassandra';\nimport { PhotoEntity } from './photo.entity';\nimport { Observable } from 'rxjs';\n\n@EntityRepository(PhotoEntity)\nexport class PhotoRepository extends Repository\u003cPhotoEntity\u003e {\n  findById(id: any): Observable\u003cPhotoEntity\u003e {\n    return this.findOne({ id: id });\n  }\n}\n```\n\nLet's have a look at the `PhotoModule`:\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { ExpressCassandraModule } from '@iaminfinity/express-cassandra';\nimport { PhotoService } from './photo.service';\nimport { PhotoController } from './photo.controller';\nimport { PhotoEntity } from './photo.entity';\nimport { PhotoRepository } from './photo.repository';\n\n@Module({\n  imports: [ExpressCassandraModule.forFeature([PhotoEntity, PhotoRepository])],\n  providers: [PhotoService],\n  controllers: [PhotoController],\n})\nexport class PhotoModule {}\n```\n\nNow let's use `PhotoRepository` in `PhotoService`:\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { InjectRepository } from '@iaminfinity/express-cassandra';\nimport { PhotoEntity } from './photo.entity';\nimport { PhotoRepository } from './photo.repository';\nimport { Observable } from 'rxjs';\n\n@Injectable()\nexport class PersonService {\n  constructor(\n    @InjectRepository(PhotoRepository)\n    private readonly photoRepository: PhotoRepository,\n  ) {}\n\n  getById(id: any): Observable\u003cPhotoEntity\u003e {\n    return this.photoRepository.findById(id);\n  }\n}\n```\n\nInjecting connection:\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { InjectRepository, InjectConnection } from '@iaminfinity/express-cassandra';\nimport { PhotoEntity } from './photo.entity';\nimport { PhotoRepository } from './photo.repository';\nimport { Observable } from 'rxjs';\n\n@Injectable()\nexport class PersonService {\n  constructor(\n    @InjectConnection()\n    private readonly connection: Connection,\n    @InjectRepository(PhotoRepository)\n    private readonly photoRepository: PhotoRepository,\n  ) {}\n\n  getById(id: any): Observable\u003cPhotoEntity\u003e {\n    return this.photoRepository.findById(id);\n  }\n}\n```\n\n## Using Elassandra\nExpress cassandra support `Elassandra`. For more details [see](https://express-cassandra.readthedocs.io/en/stable/elassandra/).\n\n```typescript\n@Module({\n  imports: [\n    ExpressCassandraModule.forRoot({\n      clientOptions: {\n        // omitted other options for clarity\n      },\n      ormOptions: {\n        // omitted other options for clarity\n        migration: 'alter',\n        manageESIndex: true,\n      }\n    })\n  ],\n  providers: [...]\n})\nexport class AppModule {}\n```\n\n```typescript\nimport { Entity, Column } from '@iaminfinity/express-cassandra';\n\n@Entity\u003cPhotoEntity\u003e({\n  table_name: 'photo',\n  key: ['id'],\n  es_index_mapping: {\n    discover: '.*',\n    properties: {\n      name : {\n        type : 'string',\n        index : 'analyzed',\n      },\n    },\n  }\n})\nexport class PhotoEntity {\n  @Column({\n    type: 'uuid',\n    default: { $db_function: 'uuid()' },\n  })\n  id: any;\n\n  @Column({\n    type: 'text',\n  })\n  name: string;\n}\n```\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { ExpressCassandraModule } from '@iaminfinity/express-cassandra';\nimport { PhotoService } from './photo.service';\nimport { PhotoController } from './photo.controller';\nimport { PhotoEntity } from './photo.entity';\n\n@Module({\n  imports: [ExpressCassandraModule.forFeature([PhotoEntity])],\n  providers: [PhotoService],\n  controllers: [PhotoController],\n})\nexport class PhotoModule {}\n```\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { InjectModel, BaseModel } from '@iaminfinity/express-cassandra';\nimport { PhotoEntity } from './photo.entity';\n\n@Injectable()\nexport class PersonService {\n  constructor(\n    @InjectModel(PhotoEntity)\n    private readonly photoEntity: BaseModel\u003cPhotoEntity\u003e\n  ) {}\n\n  searchName(name: string): Promise\u003cany\u003e {\n    return new Promise((resolve, reject) =\u003e {\n      this.catModel.search({ q: `name:${name}` }, (err, response) =\u003e {\n        if (err) {\n          return reject(err);\n        } else {\n          return response(response);\n        }\n      });\n    });\n  }\n}\n```\n\n## Stay in touch\n\n- Author - [Fahim Rahman](https://github.com/ifaim)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fifaim%2Fnestjs-express-cassandra","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fifaim%2Fnestjs-express-cassandra","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fifaim%2Fnestjs-express-cassandra/lists"}