hans-sequelize-qs
v1.0.1
Published
Query string creator for hans-sequelize-api (frontend side)
Downloads
6
Readme
hans-sequelize-qs
Query string creator for hans-sequelize-api (frontend side)
Table of contents
Installing Add the package to your project
npm i hans-sequelize-qs
using yarn
yarn add hans-sequelize-qs
Example
Export qs from hans-sequelize-qs
const qs = require('hans-sequelize-qs')
using TypeScript
import qs, {QueryObject} from 'hans-sequelize-qs'
const queryObject1: QueryObject = {
filters: {
title: {
startsWith: 'front'
}
},
relations: ['Skill', 'User'],
fields: ['code', 'title'],
relationFields: {
Skill: ['title']
},
sort: 'asc:createdAt',
relationFilters: {
Skill: {
title: {
startsWith: 'HT'
}
}
},
relationSort: {
Skill: 'asc:title'
}
}
const queryObject2: QueryObject = {
filters: {
or: [
{
title: {
startsWith: 'front'
},
},
{
code: {
endsWith: 'front'
}
}
]
},
relations: 'User',
fields: ['code', 'title'],
relationFields: {
User: ['lastName']
},
pagination: {
page: 2,
pageSize: 5
}
}
console.log(qs(queryObject1))
// ?filters[title][startsWith]=front&relations[0]=Skill&relations[1]=User&fields[0]=code&fields[1]=title&relationFields[Skill][0]=title&relationFilters[title][startsWith]=HT&sort=asc:createdAt&relationSort[Skill]=asc:title
console.log(qs(queryObject2))
// ?filters[or][0][title][startsWith]=front&filters[or][1][code][endsWith]=front&relations[0]=User&fields[0]=code&fields[1]=title&relationFields[User][0]=lastName&page=2&pageSize=5