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

davenport

v2.8.2

Published

A CouchDB client for simplifying common tasks like get, list, create, update and delete. Comes complete with full TypeScript definitions.

Downloads

30

Readme

Davenport

Davenport is a CouchDB client for simplifying common tasks like get, list, create, update and delete. It comes complete with full TypeScript definitions.

Installing

You can install Davenport with either npm or Yarn:

npm install davenport --save

# Or use Yarn
yarn add davenport

Importing

Davenport can be imported via ES6-style default import syntax, or via Node's require:

// ES6
import Client from "davenport";

// require
const Client = require("davenport").Client;

Using Davenport in the browser

Davenport can be used in the browser, so long as you transpile the async functions with TypeScript or Babel. Just add the node_modules/davenport/bin/browser.js to your web page, and all functions/objects documented below will be available under the Davenport variable.

Make sure your CouchDB installation is configured to allow cross-origin resource sharing (CORS), otherwise Davenport won't be able to connect!

Enable CORS

Async/await and promises

All Davenport functions are implemented as async/awaitable promises. You'll need Node.js v4 and above to use Davenport, as Node v3 and below don't support the generators needed for async/await.

Because async/await implements a promise-like interface in ES6, you can use the functions in this library in two different ways:

With async/await:

//1. async/await
const foo = await client.get(id);

//Do something with the object

With promises:

const foo = client.get(id).then((shop) => {
    //Do something with the object.
}); 

Both methods are supported and the results won't differ. The only difference is an awaited method will throw an error if the method fails, where a promise would just fail silently unless you use .catch.

For the sake of being concise, all examples in this doc will use async/await.

Client vs configureDatabase

Davenport exports a configureDatabase function that can help you create a database, add indexes, set up design documents with views, and then returns a client ready to interact with that database. It will also check that your CouchDB server is at least version 2.0, which is required for many of the functions used by Davenport.

// ES6
import { configureDatabase } from "davenport";

// require
const configureDatabase = require("davenport").configureDatabase;

// Configure the database with an index on the 'foo' object property, and a view that lists all foos greater than 5.
const designDoc = {
    name: "list",
    views: [{
        name: "only-foos-greater-than-5",
        map: function (doc: TestObject) {
            if (doc.foo > 5) {
                emit(doc._id, doc);
            }
        }.toString(),
        reduce: "_count"
    }]
}

const client = await configureDatabase(DB_URL, {
    name: "my-foo-database",
    designDocs: [designDoc]
})

You don't need to use the configureDatabase function to interact with your database, though. If you have no need for setting up design docs or indexes, just instantiate a new Client while passing in a database URL and database name.

import Client from "davenport";

const client = new Client(DB_URL, "my-foo-database");

Typescript declarations

Using TypeScript? The TypeScript compiler will automatically pull in Davenport definitions for you when you install Davenport, as long as you're using TypeScript 2+.

Pass your CouchDoc extending interface to the configureDatabase and new Client functions to get full TypeScript support for all client methods:

import Client, { CouchDoc } from "davenport";

interface Foo extends CouchDoc {
    foo: number,
    bar: number,
}

const client = new Client<Foo>(DB_URL, "my-foo-database");
const myFoo = await client.get(id);

// TypeScript automatically knows that variable `myFoo` is a Foo object.