nest-couchbase
TypeScript icon, indicating that this package has built-in type declarations

0.0.7 • Public • Published

Description

npm version

Couchbase Modules for NestJS projects

Installation

// npm
npm i nest-couchbase

// yarn
yarn add nest-couchbase

Usage

Configure Connection

We can add this configs in ApplicationModule.ts

@Module({
    imports: [
        CouchbaseModule.forRootAsync({
            inject: [ConfigService],
            useFactory: async (configService: ConfigService) => {
                return {
                    uri: 'couchbase://<ips>',
                    username: '<user-name>',
                    password: '<password>',
                    buckets: [
                        {
                            bucket: 'sponsored-collection',
                        },
                        {
                            bucket: 'browsing-sellerads',
                        },
                    ],
                };
            },
        }),
    ],
})
export class ApplicationModule {}

Using Default Collection

import { Module } from '@nestjs/common';
import { CbTestController } from './cb-test.controller';
import { CbTestService } from './cb-test.service';
import { CouchbaseModule } from 'nest-couchbase';

@Module({
    imports: [
        CouchbaseModule.useDefaultCollectionAsync({
            selector: 'BrowsingSellerAds',
            useFactory: async () => ({
                bucket: 'browsing-sellerads',
            }),
        }),
    ],
    controllers: [CbTestController],
    providers: [CbTestService],
})
export class CbTestModule {}

Scoped Collection

import { Module } from '@nestjs/common';
import { CbTestController } from './cb-test.controller';
import { CbTestService } from './cb-test.service';
import { CouchbaseModule } from 'nest-couchbase';

@Module({
    imports: [
        CouchbaseModule.useScopedCollectionAsync({
            selector: 'BrowsingSellerAds',
            useFactory: async () => ({
                bucket: 'browsing-sellerads',
                name: 'COMMISSION',
                scope: 'affiliate',
            }),
        }),
    ],
    controllers: [CbTestController],
    providers: [CbTestService],
})
export class CbTestModule {}

Using In Service (For Default)

import { Injectable } from '@nestjs/common';
import { InjectDefaultCollection, MixinCollection } from 'nest-couchbase';

@Injectable()
export class CbTestService {
    constructor(@InjectDefaultCollection('BrowsingSellerAds') private collection: MixinCollection) {}
    get() {
        return this.collection.getMulti([
            'sponsored_collection_content:0ab91168-b646-4b7d-a672-06cdc534fe7b_10985771',
            'sponsored_collection_content:0ab91168-b646-4b7d-a672-06cdc534fe7b_11026292',
        ]);
    }
}

Using Cluster Scope Query

import { Injectable } from '@nestjs/common';
import { InjectCouchbaseCluster, Cluster } from 'nest-couchbase';

@Injectable()
export class CbTestService {
    constructor(@InjectCouchbaseCluster() private cluster: Cluster) {}
    
    get() {
        return this.cluster.query("select b.* from `browsing-sellerads` b where type = 'TAA' limit 1");
    }
}

WIP

  • Collection content type support
  • Cluster scope query support [done]
  • Benchmark results
  • getMulti, setMulti document support [done]
  • ...

Readme

Keywords

none

Package Sidebar

Install

npm i nest-couchbase

Weekly Downloads

0

Version

0.0.7

License

MIT

Unpacked Size

156 kB

Total Files

73

Last publish

Collaborators

  • idalavye