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

mutent-couchdb

v1.0.0

Published

CouchDB adapter for Mutent

Downloads

14

Readme

mutent-couchdb

JavaScript Style Guide

CouchDB adapter for Mutent.

Features

  • Single standardized API for all search types (view, _all_docs, and Mango).
  • Automatic pagination for views and Mango queries.
  • Automatic exclusion of design documents.
  • Expose raw nano instance used internally.
  • Both ESM and CommonJS support.

Example

import { Store } from 'mutent'
import CouchAdapter from 'mutent-couchdb'

const supes = new Store({
  adapter: new CouchAdapter({
    databaseName: 'supes',
    nanoOptions: {
      url: 'http://127.0.0.1:5984/'
    }
  })
})

const ashley = await supes
  .create({ name: 'Ashley Barrett' }) // spoiler!
  .unwrap()

const homelander = await supes
  .find({
    selector: { // Mango query selector
      name: 'Homelander'
    }
  })
  .unwrap()

const moreThanSeven = await supes
  .filter({
    design: 'ddoc_name', // View query
    view: 'by_group',
    key: 'The Seven'
  })
  .unwrap()

API

Exports

This module only default exports the CouchAdapter class constuctor.

import CouchAdapter from 'mutent-couchdb'

const adapter = new CouchAdapter({
  databaseName: 'supes',
  nanoOptions: {
    // see nano docs
  },
  serverScope // already-created instance of nano server scope
})

Query format

String or Array of Strings: The adapter uses the default _add_docs view to retrieve documents by their identifiers.

// direct GET /db/doc_id
const doc = await store
  .find('64fb11c4-7c33-430c-8f17-fa63fa41933c')
  .unwrap()

// use _all_docs view
const docs = await store
  .filter([
    'a3ee2134-5714-44d1-b0c5-d3ee212b7551',
    '9326f6ad-386f-4765-aaa4-35c003349584',
    '6c64b25c-26ee-439c-a535-5da8efc0cc95'
  ])
  .unwrap()

Object with selector field: If the object contains a selector property, the adapter performs a Mango query using that selector.

const docs = await store
  .filter({
    selector: { // Mango selector
      name: 'Homelander'
    },
    limit: 7,
    conflicts: true,
    stable: true
  })
  .unwrap()

Object with both view and design fields: If both view and design properties are provided, the adapter queries the specified view.

const docs = await store
  .filter({
    design: 'ddoc_name',
    view: 'view_name',
    startkey: null,
    endkey: {},
    conflicts: true,
    stable: true
  })
  .unwrap()

Default Case: If none of the above conditions are met, the adapter uses the default _all_docs view to perform the search.

const docs = await store
  .filter({ // _all_docs view is implicit
    keys: [
      'a3ee2134-5714-44d1-b0c5-d3ee212b7551',
      '9326f6ad-386f-4765-aaa4-35c003349584',
      '6c64b25c-26ee-439c-a535-5da8efc0cc95'
    ],
    conflicts: true,
    stable: true
  })
  .unwrap()

All cases are automatically paginated (and fully optimized) by readSize value. See readSize option for more info.

All other View (or Mango) options can also be specified (see CouchDB docs for more info).

Unwrap options

[readSize]: <Number>

Number of documents downloaded per-request.

Default 50.

[purge]: <Boolean>

Purge instead of "classic delete" (setting _deleted: true).

Default false.