Skip to content

Instantly share code, notes, and snippets.

@rameshbaskar
Created January 18, 2021 02:11
Show Gist options
  • Save rameshbaskar/08dde5f3c0d408ce907928623e90f9f6 to your computer and use it in GitHub Desktop.
Save rameshbaskar/08dde5f3c0d408ce907928623e90f9f6 to your computer and use it in GitHub Desktop.
NodeJS query CouchDB
import Nano from 'nano';
const {
DB_HOST,
DB_PORT,
DB_USER,
DB_PASSWORD,
DB_NAME
} = process.env
export const couch = Nano({
url: `http://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}`
});
export const connection = async () => {
await couch.db.get(DB_NAME);
return couch.db.use(DB_NAME);
};
export const queryDatabase = async (query) => {
return await (await connection()).find(query);
};
export const bulkUpdateDatabase = async (docs) => {
return await (await connection()).bulk(docs);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment