Socket
Socket
Sign inDemoInstall

@scalio-oss/nest-couchbase

Package Overview
Dependencies
1
Maintainers
6
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @scalio-oss/nest-couchbase

Couchbase module for Nest framework


Version published
Weekly downloads
2
decreased by-33.33%
Maintainers
6
Install size
40.6 kB
Created
Weekly downloads
 

Readme

Source

Couchbase for Nest

NestJS Couchbase

A Couchbase module for NestJS

 

Installation

$ npm i @scalio-oss/nest-couchbase couchbase

Usage

@scalio-oss/nest-couchbase uses couchbase as a data provider and the Repository pattern to handle all items (documents) related operations.

First, let's create an Entity:

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:

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:

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:

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<Cat>,
  ) {}

  findOne(id: string): Promise<Cat> {
    return this.catsRepository.get(id);
  }
}

License

MIT

Credits

Created by @zMotivat0r @ Scalio

About us



Keywords

FAQs

Last updated on 01 Nov 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc