{"id":15284360,"url":"https://github.com/tensoar/cassandra-orm4nest","last_synced_at":"2025-04-12T23:22:20.195Z","repository":{"id":40431513,"uuid":"366728220","full_name":"tensoar/cassandra-orm4nest","owner":"tensoar","description":"Cassandra ORM wrapper for nest.js based on cassandra-driver.js","archived":false,"fork":false,"pushed_at":"2024-09-26T08:24:09.000Z","size":224,"stargazers_count":14,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-26T17:21:25.320Z","etag":null,"topics":["cassandra","nest","nestjs","orm","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tensoar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2021-05-12T13:38:14.000Z","updated_at":"2024-09-26T08:24:06.000Z","dependencies_parsed_at":"2024-10-14T14:52:13.591Z","dependency_job_id":null,"html_url":"https://github.com/tensoar/cassandra-orm4nest","commit_stats":{"total_commits":41,"total_committers":5,"mean_commits":8.2,"dds":"0.36585365853658536","last_synced_commit":"06824475df4689f844fabd0807ed7fc883f1b271"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tensoar%2Fcassandra-orm4nest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tensoar%2Fcassandra-orm4nest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tensoar%2Fcassandra-orm4nest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tensoar%2Fcassandra-orm4nest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tensoar","download_url":"https://codeload.github.com/tensoar/cassandra-orm4nest/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248644212,"owners_count":21138570,"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","nest","nestjs","orm","typescript"],"created_at":"2024-09-30T14:54:01.626Z","updated_at":"2025-04-12T23:22:20.162Z","avatar_url":"https://github.com/tensoar.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cassandra-orm4nest\n\n[![NPM version](https://img.shields.io/npm/v/cassandra-orm4nest.svg?style=flat)](https://www.npmjs.com/package/cassandra-orm4nest)\n[![NPM monthly downloads](https://img.shields.io/npm/dm/cassandra-orm4nest.svg?style=flat)](https://npmjs.org/package/cassandra-orm4nest)\n[![NPM total downloads](https://img.shields.io/npm/dt/cassandra-orm4nest.svg?style=flat)](https://npmjs.org/package/cassandra-orm4nest)\n\nCassandra ORM wrapper for nestjs based on `cassandra-driver` package.\n\n[中文说明](./README_CN.md)\n\n## Install\n\nuse npm:\n\n```bash\nnpm i cassandra-orm4nest --save\n```\n\nuse yarn:\n\n```bash\nyarn add cassandra-orm4nest\n```\n\n## Usage\n\n### Entity Definition\n\nuse `@Entity` and `@Column` decorator define an entity:\n\n```typescript\n// device.entity.ts\nimport { Column, Entity } from \"cassandra-orm4nest\";\n\n@Entity({\n    keyspace: 'test',\n    table: 'device'\n})\nexport default class Device {\n    @Column({name: 'serial_number'})\n    serialNumber: string;\n\n    @Column({name: 'create_time'})\n    createTime: Date;\n\n    @Column()\n    version: string;\n\n    @Column({name: 'is_online'})\n    isOnline: boolean;\n}\n```\n\n### Module Definition\n\nJust like typeorm, you can use `forRoot` method to configure the database and use `forFeature` method to register entities:\n\n```typescript\n// orm-test.module.ts\nimport { Module } from \"@nestjs/common\";\nimport { auth } from \"cassandra-driver\";\n\nimport { CassandraOrmModule } from \"cassandra-orm4nest\";\nimport DeviceController from \"device.controller\";\nimport Device from \"device.entity\";\nimport DeviceService from \"device.service\";\n\n@Module({\n    imports: [\n        CassandraOrmModule.forRoot({ // database configuration\n            contactPoints: ['localhost'],\n            authProvider: new auth.PlainTextAuthProvider('username', 'password'),\n            localDataCenter: 'datacenter1'\n        }),\n        CassandraOrmModule.forFeature([ // register entities\n            Device\n        ])\n    ],\n    controllers: [DeviceController], // related controller\n    providers: [DeviceService] // related service\n})\nexport default class OrmTestModule {}\n```\n\n### Service Defination\n\nEntities registered in `forFeature` method will generate corresponding mapper objects witch type is mapping.ModelMapper and can be injected by `@InjectMapper` decorator.\n\n```typescript\nimport { Injectable } from \"@nestjs/common\";\nimport { Client } from \"cassandra-driver\";\n\nimport { InjectClient, InjectMapper, BaseService } from \"cassandra-orm4nest\";\nimport Device from \"device.entity\";\n\n@Injectable()\nexport default class DeviceService extends BaseService\u003cDevice\u003e {\n    constructor(\n        @InjectMapper(Device) private readonly mapper, // inject mapper object\n        @InjectClient() client: Client // inject cassandra connection client\n    ) {\n        super(client, mapper, Device); // inherit the parent class constructor\n    }\n}\n```\n\nAs you can see, we can extend the `BaseService` class that implements the basic CRUD methods, includes:\n\n* `saveOne`: Save a single entity.\n* `saveMany`: Save multiple entities.\n* `finadAll`: Query the full table, it is quivalent to the `findAll` method in the `ModelMapper` class in `cassandra-driver`, there is a limit on the number of results for a single query, default is 5000.\n* `findRealAll`: Query the full table, unlike `findAll`, there is no limit on the number of results for a single query, because it will converted to `eachRow` method to perform query operations.\n* `findMany`: Query based on conditions, it is quivalent to the `find` method in the `ModelMapper` class in `cassandra-driver`, there is a limit on the number of results for a single query, default is 5000.\n* `findRealMany`:  Query based on conditions, unlike `findMany`, there is no limit on the number of results for a single query, because it will converted to `eachRow` method to perform query operations.\n* `findOne`: : Query based on conditions, return the first item that meets the condition.\n* `update`: Update based on conditions, it is quivalent to the `update` method in the `ModelMapper` class in `cassandra-driver`.\n* `updateMany`: Perform multiple conditional update operations.\n* `remove`: Remove based on conditions, it is quivalent to the `remove` method in the `ModelMapper` class in `cassandra-driver`.\n* `removeMany`: Perform multiple conditional remove operations.\n* `delete`: delete use origin cql, can not write all primary keys\n\n### Usage In Controller\n\nInject service directly into the control layer:\n\n```typescript\n// device.controller.ts\nimport DeviceService from \"device.service\"\nexport default class DeviceController {\n    constructor(\n        private readonly deviceService: DeviceService // inject\n    ){}\n\n    @Get('doSomthing')\n    async doSomething() {\n        // TODO\n    }\n}\n```\n\n## Test Demo\n\nThere is a demo in test folder.\n\nImport schema:\n\n```bash\n cqlsh \u003chost\u003e -u \u003cusername\u003e -p \u003cpassword\u003e \u003c test/schema.cql\n```\n\nRun test server:\n\n```bash\nnpm run test -- --host \u003cdb host\u003e --username \u003cdb username\u003e --password \u003cdb password\u003e --datacenter \u003cdb datacenter\u003e\n```\n\nAccess URL in the browser:\n\n```bash\nhttp://localhost:30000/device/doSomthing\n```\n\n## Thanks\n\n* JetBrains for free open source licenses\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftensoar%2Fcassandra-orm4nest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftensoar%2Fcassandra-orm4nest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftensoar%2Fcassandra-orm4nest/lists"}