Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sequelize-search-builder-client

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sequelize-search-builder-client

This is a library for the generation search http request for [Sequelize Search Builder](https://github.com/segemun/sequelize-search-builder) module.

  • 0.2.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
15
decreased by-55.88%
Maintainers
1
Weekly downloads
 
Created
Source

Sequelize Search Builder Client

About

This is a library for the generation search http request for Sequelize Search Builder module.

Installation

npm install --save sequelize-search-builder-client

Usage

import generateSearchRequest from 'sequelize-search-builder-client';

Simple one field example

const formData = {
    name: 'John',
};
const settings = {
    where: {
        name: {
            as: 'fname',
            type: 'like',
        },
    },
};
const request = generateSearchRequest(data, settings);
// request data:
{
    filter: {
        fname: {
            like: '%John%',
        },
    },
}

With conditions

const formData = {
    name: 'John',
    age: {
        firstValue: 18,
        secondValue: 21,
    },
};
const settings = {
    where: {
        _condition: 'or',
        name: {
            as: 'fname',
            type: 'like',
        },
        age: {
            _condition: 'or',
            types: [{
                type: 'lte',
                by: 'firstValue',
            }, {
                type: 'gte',
                by: 'secondValue'
            }]
        },
    },
};
const request = generateSearchRequest(data, settings);
// request data:
{
    filter: {
        fname: {
            like: '%John%',
        },
        age: {
            lte: 18,
            gte: 21,
            _condition: 'or',
        },
        _condition: 'or',
    },
}

Order, limit and offset params

const settings = {
    where: {...},
    order: {
        name: 'desc',
    },
    limit: 10,
    offset: 10;
}

Equal operator example

const formData = {
    name: 'John',
};
const settings = {
  where: {
    name: {
        type: 'equal',  
    },
  },
};

Gt, Gte, Lt, Lte, ne, like, iLike, notLike, notILike, regexp, notRegexp, iRegexp, notIRegexp operators examples

const formData = {
    age: 18,
};
const settings = {
  where: {
    age: {
        type: 'gt', // (gte, lt, lte, ne, like, iLike, notLike, notILike, regexp, notRegexp, iRegexp, notIRegexp)  
    },
  },
};

In, notIn operator example

const formData = {
    authors: [{
        name: 'John',
    }, {
        name: 'Bob',   
    }]
};
const settings = {
  where: {
    authors: {
        type: 'in', // notIn
        itemBy: 'name', // 'id' by default
    },
  },
};

Between, notBetween operator example

const formData = {
    author: {
        firstValue: 21,
        secondValue 33:
    },
};
const settings = {
  where: {
    authors: {
        type: 'between', // notBetween
        startBy: 'firstValue', // 'start' by default
        endBy: 'secondValue', // 'end' by default
    },
  },
};

Contribute

You are Welcome =) Keep in mind:

npm run test

FAQs

Package last updated on 22 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc