This is a library for the generation search http request for Sequelize Search Builder module.
npm install --save sequelize-search-builder-client
import generateSearchRequest from 'sequelize-search-builder-client';
const formData = {
name: 'John',
};
const settings = {
where: {
name: {
as: 'fname',
type: 'like',
},
},
};
const request = generateSearchRequest(formData, settings);
// request data:
{
filter: {
fname: {
like: '%John%',
},
},
}
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(formData, settings);
// request data:
{
filter: {
fname: {
like: '%John%',
},
age: {
lte: 18,
gte: 21,
_condition: 'or',
},
_condition: 'or',
},
}
const settings = {
where: {...},
order: {
name: 'desc',
},
limit: 10,
offset: 10;
}
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)
},
},
};
const formData = {
authors: [{
name: 'John',
}, {
name: 'Bob',
}]
};
const settings = {
where: {
authors: {
type: 'in', // notIn
itemBy: 'name', // 'id' by default
},
},
};
const formData = {
author: {
firstValue: 21,
secondValue 33:
},
};
const settings = {
where: {
authors: {
type: 'between', // notBetween
startBy: 'firstValue', // 'start' by default
endBy: 'secondValue', // 'end' by default
},
},
};
You are Welcome =) Keep in mind:
npm run test