1.2.0 • Published 4 months ago

nest-ottoman v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

Nestjs Ottoman

GitHub

Ottoman module for Nestjs

Features

  • Model support
  • Simply add @InjectModel(ModelName) to your service and you are ready to go

Installation

Yarn

yarn add nest-ottoman ottoman

NPM

npm install nest-ottoman ottoman --save

PNPM

pnpm add nest-ottoman ottoman

Usage

Module Registration

import { Module } from '@nestjs/common';
import { OttomanModule } from 'nest-ottoman';

@Module({
  imports: [
    OttomanModule.forRoot({
      connectionString: 'couchbase://localhost',
    }),
  ],
})

export class AppModule {}

Async registration is also available:

import { Module } from '@nestjs/common';
import { OttomanModule } from 'nest-ottoman';

@Module({
  imports: [
    OttomanModule.forRootAsync({
      useFactory: () => ({
        connectionString: 'couchbase://localhost',
      }),
    }),
  ],
})

export class AppModule {}

Model Registration

@Property decorator is ottoman property decorator. More information about decorators can be found here

import { Model, Property } from 'nest-ottoman';

@Model('_default')
export class DefaultModel {
  @Property()
  id: string;

  @Property()
  property: string;
}

Service Registration

import { Injectable } from '@nestjs/common';
import { DefaultModel } from './collections/foo.collection';
import { Model, InjectModel } from 'nest-ottoman';

@Injectable()
export class AppService {
  constructor(
    @InjectModel(DefaultModel)
    private readonly defaultModel: Model<DefaultModel>,
  ) {}
  
  findAll(): Promise<DefaultModel[]> {
    return this.defaultModel.find();
  }
}

Decorators

DecoratorDescription
@ModelClass(bucketName: string)Decorator for model registration
@Property()Decorator for property registration

Nest Ottoman Module Options

OptionDescription
connectionString: stringCouchbase connection string
connector?: stringCouchbase connector name
ottomanConfig?: typeof Ottoman.prototype.configOttoman config
retryAttempts?: numberNumber of retry attempts
retryDelay?: numberDelay between retry attempts

Example Application

Example application can be found here