https://github.com/vanioinformatika/node-nano-async
Async wrap for nano (couchdb client)
https://github.com/vanioinformatika/node-nano-async
async javascript nano node promise typescript
Last synced: 7 months ago
JSON representation
Async wrap for nano (couchdb client)
- Host: GitHub
- URL: https://github.com/vanioinformatika/node-nano-async
- Owner: vanioinformatika
- Created: 2017-09-05T06:03:49.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-12-11T13:48:54.000Z (almost 8 years ago)
- Last Synced: 2025-03-08T06:34:12.954Z (7 months ago)
- Topics: async, javascript, nano, node, promise, typescript
- Language: TypeScript
- Size: 72.3 KB
- Stars: 0
- Watchers: 7
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
[](https://coveralls.io/github/vanioinformatika/node-nano-async?branch=master)
[](https://travis-ci.org/vanioinformatika/node-nano-async)# node-nano-async
A promisified wrapper around the [nano](http://npmjs.com/package/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
```js
const { default: nanoAsync } = require('nano-async')
// Create a server context
const serverScope = 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
```ts
// 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 = serverAsync.use("mydb")// Read a document from the database
const [doc, headers] = await databaseAsync.getAsync(id, { attachments: true })
// doc is of type: DocumentGetResponse & MyDocument...
```