0.0.4 • Published 6 years ago

@blacksmithstudio/blockbase-elasticsearch v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

Driver Elasticsearch for Blockbase

Compatible with Blockbase Framework

Version

0.0.4 alpha

How to install ?

$ npm i --save @blacksmithstudio/blockbase-elasticsearch

Then add to your config/{env}.yml the following instructions depending of your system

dbms : elasticsearch
elasticsearch :
    host : localhost:9200
    index : myindex

In your models, you just have to setup the type (refering to the type in ES) and the index from your config, example below :

module.exports = (app) => {
    const Model = app.models._model
    const Config = app.config

    return class User extends Model {
        /**
         * main constructor
         * @param {Object} data - data to param the model
         */
        constructor(data) {
            // for example I have myindex as index & user as type in ES
            super({ type: 'user', index : Config.elasticsearch.index })

            if (data)
                this.data = data
        }
    }
}

The use what you want in your usage as a classic Blockbase model. For example here is an example controller from express, receiving data.

module.exports = (app) => {
    const User = app.models.user

    return {
        async create(req, res){
            const { firstname, lastname, email } = req.body

            let user = new User({ firstname, lastname, email })
            try{
                user = await user.save()
                console.log(user.data.id) // here you get your ES id
            }
        }
    }
}

Unit tests

$ npm run test

License

(Copyright) 2018 - Alexandre Pereira for Blacksmith S.A.S.

Free Software, Hell Yeah!

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

7 years ago

0.0.1

7 years ago