0.2.1 • Published 1 year ago
@mateonunez/fastify-lyra v0.2.1
fastify-lyra
Lyra plugin for Fastify.
Installation
npm install @mateonunez/fastify-lyra
Usage
Example
const Fastify = require('fastify')
const FastifyLyra = require('@mateonunez/fastify-lyra')
const app = Fastify()
app.register(FastifyLyra, {
schema: {
quote: "string",
author: "string"
}
})
app.get('/quotes/:query', async function (req, reply) {
try {
const { params: { query } } = req
const search = app.lyra.search({
term: query,
properties: ["quote"]
})
return { quotes: search.hits }
} catch (err) {
return err;
}
})
app.listen(3000)
Usage with data persistence
This plugin implements @lyrasearch/plugin-data-persistence to allow users to load
or save
database instances.
Example
const Fastify = require('fastify')
const FastifyLyra = require('@mateonunez/fastify-lyra')
const app = Fastify()
// The database must exists to load it in your Fastify application
app.register(FastifyLyra, {
persistence: true,
persistency: {
name: './quotes.json',
format: 'json'
}
})
app.post('/quotes', async function (req, reply) {
try {
const { body: { author, quote } } = req
fastify.lyra.insert({
author,
quote
})
fastify.lyra.save()
return { success: true }
} catch (err) {
return err;
}
})
app.listen(3000)
License
FastifyLyra is licensed under the MIT license.
0.2.1
1 year ago
0.2.0
1 year ago
0.1.0
2 years ago
0.1.2
2 years ago
0.1.1
2 years ago
0.1.3
2 years ago
0.0.5
2 years ago
0.0.4
2 years ago
0.0.3
2 years ago
0.0.2
2 years ago
0.0.1-beta.6
2 years ago
0.0.1-beta.5
2 years ago
0.0.1-beta.4
2 years ago
0.0.1-beta.3
2 years ago
0.0.1-beta.2
2 years ago
0.0.1-beta.1
2 years ago
0.0.1-beta.0
2 years ago
0.0.1
2 years ago