1.0.3 • Published 7 years ago

nano-async v1.0.3

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

Coverage Status Build Status

node-nano-async

A promisified wrapper around the nano npm module, to make it easily usable with ES2017 async-await.

The wrapper introduces new functions with 'Async' suffix to make using the original nano functions possible. It can be handy when you read/write attachments in streaming mode.

Usage

Javascript

const nanoAsync = require('nano-async') (
  // Create a server context
const serverAsync = nanoAsync({ url: "http://localhost:5984" })
// Create a document context i.e. a "database" reference
const databaseAsync = serverScope.use("mydb")

// Read a document from the database
const [doc, headers] = await databaseAsync.getAsync(id, { attachments: true })

...

TypeScript

// Import nano and nano-async types
import { default as nanoAsync, ServerScopeAsync, DocumentGetResponse, ... } from "nano-async"
// Import custom document class
import { MyDocument } from "./MyDocument"
// Create a server context
const serverAsync = nanoAsync({ url: "http://localhost:5984" }) as ServerScopeAsync
// Create a document context i.e. a "database" reference
const databaseAsync: DocumentScopeAsync<MyDocument> = serverAsync.use<MyDocument>("mydb")

// Read a document from the database
const [doc, headers] = await databaseAsync.getAsync(id, { attachments: true })
// doc is of type: DocumentGetResponse & MyDocument

...