Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mcollina/fastify-massive
Massive.js plugin for Fastify
https://github.com/mcollina/fastify-massive
Last synced: about 1 month ago
JSON representation
Massive.js plugin for Fastify
- Host: GitHub
- URL: https://github.com/mcollina/fastify-massive
- Owner: mcollina
- License: mit
- Created: 2018-04-07T08:51:57.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-06-22T21:53:50.000Z (over 2 years ago)
- Last Synced: 2024-11-01T12:42:21.993Z (about 2 months ago)
- Language: JavaScript
- Size: 10.7 KB
- Stars: 15
- Watchers: 3
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fastify-massive
[Massive.js][massive] plugin for [Fastify](https://www.fastify.io/).
## Install
`npm i fastify-massive`
## Usage
```js
'use strict'const Fastify = require('fastify')
const massive = require('fastify-massive')
const fastify = Fastify()
fastify.register(massive, {
massive: connInfo,
async onLoad(db) {
// DB is a connected Massive instance;
// use this hook to set up your database
// if it is needed.
// We will reload the meta-info after
// this is completed.
}
})fastify.get('/', async (req, res) => {
// list available tables
return fastify.massive.listTables()
})fastify.post('/', async (request, reply) => {
// pages is a document table provided by massive.js
const { pages } = fastify.massive// findDoc is a massive.js API to work
// with documents
const root = await pages.findDoc({
title: 'root'
})
if (!root) {
root = {}
}
root.body = request.body// saveDoc performs an upsert to create or update
// the document as appropriate
await pages.saveDoc(root)reply.code(204)
return ''
})
```## License
MIT
[massive]: https://github.com/dmfay/massive-js