I want Query Function That I can pass in FindAll Query To Get Daynamic data
Example: If I want to get data like age>5 then direct I can get using query paramas
This is just example
At the end I want query funcatuion that can genrate dynamic query on query params
I have made this funcation for daynamic sort, and paggination
const usersqquery = (q) => {
const limit = q?.limit * 1 || 200;
const page = q?.page * 1 || 1;
const skip = (page - 1) * limit;
const sort = q?.sort || "createdAt";
const sortBy = q?.sortBy || "DESC";
if (q?.limit) {
return { order: [[sort, sortBy]], limit, offset: skip };
}
return { order: [[sort, sortBy]] };
};
I want more acurate funcation for genrate dynamic query
i've been through the same problem but in my case with typeorm but i think my solution will works for you. what i did is implement simple parser that take
stingifiedJsonObjectQuerywhich is JSON string that represent where from client and parse it's to typeorm object. that's snippet from my production code that does the jobs:(and please note that this is not for copy paste it just to looks at and to learn from)