nano-async
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

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

...

Readme

Keywords

none

Package Sidebar

Install

npm i nano-async

Weekly Downloads

0

Version

1.0.3

License

MIT

Last publish

Collaborators

  • gyszalai
  • vanioinformatika
  • vincekovacs