Created
January 18, 2021 02:11
-
-
Save rameshbaskar/08dde5f3c0d408ce907928623e90f9f6 to your computer and use it in GitHub Desktop.
NodeJS query CouchDB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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