# nest-ottoman

> Ottoman module for Nestjs

Latest version **1.2.0** (published 2024-01-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install nest-ottoman
pnpm add nest-ottoman
yarn add nest-ottoman
bun add nest-ottoman
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2024-01-24 |
| First published | 2024-01-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 140.8 KB |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| Author | Ramazan |
| Maintainers | andromeda606 |

## Links

- npm: https://www.npmjs.com/package/nest-ottoman
- Repository: https://github.com/Andromeda606/nest-ottoman
- Homepage: https://github.com/Andromeda606/nest-ottoman#readme
- Issues: https://github.com/Andromeda606/nest-ottoman/issues
- npm.io page: https://npm.io/package/nest-ottoman

## Dependencies (6)

- [rxjs](https://npm.io/package/rxjs.md) ^7.2.0
- [@nestjs/core](https://npm.io/package/@nestjs/core.md) 9.0.5
- [@nestjs/common](https://npm.io/package/@nestjs/common.md) 9.0.5
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.13
- [@nestjs/mapped-types](https://npm.io/package/@nestjs/mapped-types.md) *
- [@nestjs/platform-express](https://npm.io/package/@nestjs/platform-express.md) ^9.0.0

## Recent versions

- 1.2.0 (latest) — 2024-01-24
- 1.1.0 — 2024-01-24
- 1.0.1 — 2024-01-18
- 1.0.0 — 2024-01-18

## README

# Nestjs Ottoman
![GitHub](https://img.shields.io/github/license/Andromeda606/nest-ottoman)

> Ottoman module for Nestjs 

## Features
- Model support
- Simply add `@InjectModel(ModelName)` to your service and you are ready to go

## Installation

### Yarn
```bash
yarn add nest-ottoman ottoman
```

### NPM
```bash
npm install nest-ottoman ottoman --save
```

### PNPM
```bash
pnpm add nest-ottoman ottoman
```

## Usage
### Module Registration
```typescript
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:
```typescript
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](https://ottomanjs.com/docs/basic/schema.html)
```typescript
import { Model, Property } from 'nest-ottoman';

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

  @Property()
  property: string;
}
```

### Service Registration
```typescript
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
| Decorator                         | Description                         |
|-----------------------------------|-------------------------------------|
| `@ModelClass(bucketName: string)` | Decorator for model registration    |
| `@Property()`                     | Decorator for property registration |

## Nest Ottoman Module Options
| Option                                            | Description                  |
|---------------------------------------------------|------------------------------|
| `connectionString: string`                        | Couchbase connection string  |
| `connector?: string`                              | Couchbase connector name     |
| `ottomanConfig?: typeof Ottoman.prototype.config` | Ottoman config               |
| `retryAttempts?: number`                          | Number of retry attempts     |
| `retryDelay?: number`                             | Delay between retry attempts |



## Example Application
Example application can be found [here](https://github.com/Andromeda606/nest-ottoman/tree/master/example)

---
_Source: https://npm.io/package/nest-ottoman · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
