npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@irieimperator/nest-couch

v1.0.0

Published

NestJS module acting as a wrapper around nano providing a convenient 'NestJS style' approach for using CouchDB.

Downloads

1

Readme

This module acts as a wrapper around nano providing a convenient "NestJS style" approach for using CouchDB. nano is Apaches official NodeJS library with TypeScript support.

Installation

npm i @irieimperator/nest-couch

Configuration

Options

Since it is a wrapper, you can use all options provided in nano. To establish a connection, you need at least:

| parameter | type | required | description | |-----------|------|----------|-------------| | nano.url | string | true | url to connect to CouchDB, ex. https://USER:PASSWORD@HOST:PORT |

In addition, nest-couch accepts additional parameters:

| parameter | type | required | description | |-----------|------|----------|-------------| | defaultBucket | string | false | name of the default bucket you want to use | | buckets | string[] | false | names of buckets you want to use | | logging.level | 'OFF' or 'INFO' | false | controls level of logging |

Import

This module can be imported and configured both synchronously and asynchronously.

synchron

NestCouchModule.register({
      nano: {
        url: 'https://USER:PASSWORD@HOST:PORT'
      },
      defaultBucket: 'cats',
      buckets: ['dogs', 'beavers', 'chinchillas'],
      logging: {
        level: 'INFO'
      }
})

asynchron

NestCouchModule.registerAsync({
  inject: [ConfigService],
  useFactory: (configService: ConfigService) => {
    return {
      nano: {
        url: configService.get<string>('DB_URL')
      },
      defaultBucket: configService.get<string>('DB_DEFAULT_BUCKET'),
      buckets: configService.get<string>('DB_BUCKETS').split(','),
      logging: {
        level: configService.get<'OFF' | 'INFO'>('DB_LOG_LEVEL')
      }
    };
  }
})

Usage

Depending on the configuration you have access to the following:

| injected property | type | exists | description | |-----------|------|----------|-------------| | NEST_COUCH_CONNECTION | nano connection instance | always | / | | NEST_COUCH_DEFAULT_BUCKET | nano.db.use(defaultBucket) | if specified | / | | NEST_COUCH_BUCKETS | multiple nano.db.use(bucket) | if specified | returns an object holding a nano.db.use(bucket) for each specified bucket, with the bucket name as key |

You can use nest-couch in a service like that:

@Injectable()
export class AppService {
    constructor(
        @Inject(NEST_COUCH_CONNECTION) private readonly connection,
        @Inject(NEST_COUCH_DEFAULT_BUCKET) private readonly bucket,
        @Inject(NEST_COUCH_BUCKETS) private readonly buckets
    ) {}
    
    // use connection - create new bucket
    async createBucket(bucket: string) {
      await this.connection.db.create(bucket);
    }

    // use defaultBucket - list all objects
    async createBucket() {
      await this.bucket.list();
    }
    
    // use one of the other buckets - insert object
    async createBucket(bucket: string, object: MySpecialObject) {
      await this.buckets[bucket].insert(object);
    }
}

Thanks

The basic structure of this module was created with nestjsplus' dynamic module generator - thanks for saving the effort, works like a charm!