You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@bryopsida/nest-couchdb

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bryopsida/nest-couchdb

CouchDB module for Nest framework

0.4.0
latest
npmnpm
Version published
Maintainers
1
Created
Source

NestJS CouchDB

Quality Gate Status Coverage Security Rating Vulnerabilities Code Smells Bugs

A CouchDB module for NestJS

Installation

$ npm i @bryopsida/nest-couchdb nano

Usage

@bryopsida/nest-couchdb uses nano as a data provider for CouchDB and the Repository pattern to handle all documents related operations.

First, let's create an Entity:

import { Entity, CouchDbEntity } from '@bryopsida/nest-couchdb'

@Entity('cats')
export class Cat extends CouchDbEntity {
  name: string
}

Where cats is the CouchDB database name.

The CouchDbEntity is a base class which has some common properties:

class CouchDbEntity {
  _id: string
  _rev: string
}

Then, we need to import CouchDbModule in our ApplicationModule:

import { Module } from '@nestjs/common'
import { CouchDbModule } from '@bryopsida/nest-couchdb'

@Module({
  imports: [
    CouchDbModule.forRoot({
      url: 'http://localhost:5984',
      username: 'couchdb',
      userpass: 'password',
      requestDefaults: { jar: true },
    }),
  ],
})
export class ApplicationModule {}

In our CatsModule we need to initiate repository for our Cat entity:

import { Module } from '@nestjs/common'
import { CouchDbModule } from '@bryopsida/nest-couchdb'
import { CatsService } from './cats.service'
import { CatsController } from './cats.controller'
import { Cat } from './cat.entity'

@Module({
  imports: [CouchDbModule.forFeature([Cat])],
  providers: [CatsService],
  controllers: [CatsController],
})
export class CatsModule {}

And here is the usage of the repository in the service:

import { DocumentListResponse } from 'nano';
import { Injectable } from '@nestjs/common';
import { InjectRepository, Repository } from '@bryopsida/nest-couchdb';
import { Cat } from './cat.entity';

@Injectable()
export class CatsService {
  constructor(
    @InjectRepository(Cat)
    private readonly catsRepository: Repository<Cat>,
  ) {}

  findAll(): Promise<DocumentListResponse<Cat> {
    return this.catsRepository.list();
  }
}

Test

$ docker-compose up -d
$ npm test

License

MIT

Credits

Created by @zMotivat0r @ Scalio

Keywords

nestjs

FAQs

Package last updated on 04 Jul 2023

Did you know?

Socket

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