ilorm-plugin-algolia

0.1.1 • Public • Published

ilorm-plugin-algolia

This plugin adds binding between your data and algolia.

Schema

With this plugin enabled you can define which fields will be stored in your database and in algolia.

const { Schema } = require('ilorm');
 
const userSchema = new Schema({
  email: Schema.string().required().algolia(),
  firstName: Schema.string().required().algolia()
})

Declare model index

const algoliasearch = require('algoliasearch');
const { newModel } = require('ilorm');
 
const client = algoliasearch(CLIENT_ID, CLIENT_SECRET);
 
const UserModel = newModel({
  name: 'users',
  schema: userSchema,
  pluginsOptions: {
    algolia: {
      index: client.index('users'),
    },
  },
  connector: // ...
})

Search

With algolia enabled on your model, you will have a new search method on the query

const User = require('./user.model');
 
const user = await User.query()
    .search('smith')
    .findOne();

How it's work?

  • At save and remove classic model method, the associated algolia index will be updated (upsert instance or remove from index).
  • At query, the Query will first search in algolia, and filtering with the returning ObjectId the query to the main database.

Package Sidebar

Install

npm i ilorm-plugin-algolia

Weekly Downloads

2

Version

0.1.1

License

ISC

Last publish

Collaborators

  • stombre