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);
{
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);
{
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',
},
},
};
In, notIn operator example
const formData = {
authors: [{
name: 'John',
}, {
name: 'Bob',
}]
};
const settings = {
where: {
authors: {
type: 'in',
itemBy: 'name',
},
},
};
Between, notBetween operator example
const formData = {
author: {
firstValue: 21,
secondValue 33:
},
};
const settings = {
where: {
authors: {
type: 'between',
startBy: 'firstValue',
endBy: 'secondValue',
},
},
};
Contribute
You are Welcome =)
Keep in mind:
npm run test