Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/offgriddev/fastify-cosmosdb
CosmosDb Plugin for Fastify. Allows for a simple interface to quickly access Azure CosmosDb containers through the Fastify instance.
https://github.com/offgriddev/fastify-cosmosdb
Last synced: about 1 month ago
JSON representation
CosmosDb Plugin for Fastify. Allows for a simple interface to quickly access Azure CosmosDb containers through the Fastify instance.
- Host: GitHub
- URL: https://github.com/offgriddev/fastify-cosmosdb
- Owner: offgriddev
- Created: 2021-10-12T02:36:28.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2021-10-18T18:11:15.000Z (about 3 years ago)
- Last Synced: 2024-09-14T10:52:04.409Z (2 months ago)
- Language: TypeScript
- Homepage:
- Size: 168 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# Fastify-cosmosDb: Your Fastify Plugin for Azure CosmosDb
This Fastify plugin interogates your CosmosDb account to determine which containers are available and provides quick access through a Fastify Instance decoration. This plugin integrates with [@azure/cosmosdb](https://www.npmjs.com/package/@azure/cosmos) and allows you to specify the database filters to opt-in account resources.
## Install
```
npm i fastify-cosmosdb -S
```
## UsageFor unfiltered access to all cosmos containers.
Configuration without database and container filters:
```js
const fastify = require('fastify')fastify.register(require('fastify-cosmosdb'), {
cosmosOptions: {
endpoint: 'your-account-endpoint',
authKey: 'auth-key'
}
})fastify.listen(3000, err => {
if (err) throw err
console.log(`server listening on ${fastify.server.address().port}`)
})
```Configuration with database and container filters:
```js
const fastify = require('fastify')fastify.register(require('fastify-cosmosdb'), {
cosmosOptions: {
endpoint: 'your-account-endpoint',
authKey: 'auth-key'
},
databases: [{
id: 'database-id',
containers: {
'container-name': true
}
}]
})fastify.listen(3000, err => {
if (err) throw err
console.log(`server listening on ${fastify.server.address().port}`)
})
``````js
async function singleRoute(fastify, options) {
fastify.get(
'/users/:id',
(request, reply) => {
// containers accessible through 'cosmosDbContainers'
return fastify.cosmos.databaseId.containerName.items('item-id', 'partition-key')
},
)
}
```## License
Licensed under [MIT](./LICENSE).