fastify-pouchdb
v1.0.3
Published
Fastify PouchDB Plugin
Downloads
5
Readme
fastify-pouchdb
Fastify plugin to use PouchDB
Install
npm install fastify-pouchdb --save
npm install @types/pouchdb --save-dev
Usage
import * as fastify from 'fastify';
import fastifyPouchDB from 'fastify-pouchdb';
const server: fastify.FastifyInstance<Server, IncomingMessage, ServerResponse> = fastify({
logger: true,
});
server.register(fastifyPouchDB, {
name: 'myleveldb',
});
server.get('/', async (request, reply) => {
try {
const result = await server.pouchdb.allDocs();
return {
error: 0,
data: result,
};
} catch (e) {
return {
error: 1,
msg: e.message,
};
}
});
server.get('/put', async (request, reply) => {
try {
const result = await server.pouchdb.put({
_id: 'mydoc',
title: 'Heroes',
});
return {
error: 0,
data: result,
};
} catch (e) {
return {
error: 1,
msg: e.message,
};
}
});
server.listen(3000, (err, address) => {
if (err) {
server.log.error(err);
process.exit(1);
}
server.log.info(`server listening on ${address}`);
});