Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/scalio/nest-couchbase
Couchbase module for NestJS
https://github.com/scalio/nest-couchbase
couchbase database nest nestjs nodejs orm
Last synced: about 2 months ago
JSON representation
Couchbase module for NestJS
- Host: GitHub
- URL: https://github.com/scalio/nest-couchbase
- Owner: scalio
- License: mit
- Created: 2019-07-22T07:53:27.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T07:21:22.000Z (almost 2 years ago)
- Last Synced: 2024-11-01T07:41:12.754Z (about 2 months ago)
- Topics: couchbase, database, nest, nestjs, nodejs, orm
- Language: TypeScript
- Size: 1.43 MB
- Stars: 20
- Watchers: 22
- Forks: 9
- Open Issues: 19
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![Couchbase for Nest](https://raw.githubusercontent.com/scalio/nest-couchbase/master/scalio-nc.svg?sanitize=true)
NestJS Couchbase
## Installation
```bash
$ npm i @scalio-oss/nest-couchbase couchbase
```## Usage
`@scalio-oss/nest-couchbase` uses [couchbase](https://www.npmjs.com/package/couchbase) as a data provider and the `Repository` pattern to handle all items (documents) related operations.
First, let's create an `Entity`:
```typescript
import { Entity } from '@scalio-oss/nest-couchbase';@Entity('cats')
export class Cat {
name: string;
}
```Where `cats` is the Couchbase bucket name (optional).
Then, we need to import `CouchbaseModule` in our root `AppModule`:
```typescript
import { Module } from '@nestjs/common';
import { CouchbaseModule } from '@scalio-oss/nest-couchbase';@Module({
imports: [
CouchbaseModule.forRoot({
url: 'couchbase://127.0.0.1',
username: 'couchbase',
password: 'couchbase',
defaultBucket: {
name: 'test',
password: 'password',
},
buckets: [
{
name: 'another_bucket',
password: 'another_password',
},
],
}),
],
})
export class AppModule {}
```In our `CatsModule` we need to initiate repository for our `Cat` entity:
```typescript
import { Module } from '@nestjs/common';
import { CouchbaseModule } from '@scalio-oss/nest-couchbase';
import { CatsService } from './cats.service';
import { CatsController } from './cats.controller';
import { Cat } from './cat.entity';@Module({
imports: [CouchbaseModule.forFeature([Cat])],
providers: [CatsService],
controllers: [CatsController],
})
export class CatsModule {}
```And here is the usage of the repository in the service:
```typescript
import { Injectable } from '@nestjs/common';
import { InjectRepository, Repository } from '@scalio-oss/nest-couchbase';
import { Cat } from './cat.entity';@Injectable()
export class CatsService {
constructor(
@InjectRepository(Cat)
private readonly catsRepository: Repository,
) {}findOne(id: string): Promise {
return this.catsRepository.get(id);
}
}
```## License
[MIT](LICENSE)
## Credits
Created by [@zMotivat0r](https://github.com/zMotivat0r) @ [Scalio](https://scal.io/)
## About us