Kuuliza means "query" in Swahili.
This package exposes Sequelize querying abilities from a simple params object. It is designed to be and stay simple !!!
Here is an example:
QueryBuilder.build({
filters: {
assignations: { is: null },
companyIdentifier: { not: null },
alertShortId: 'ALERT_SHORT_ID',
eventShortId: [
'EVENT_SHORT_ID_1',
'EVENT_SHORT_ID_2',
'EVENT_SHORT_ID_3'
],
indexedMeta: {
eventType: 'EVENT_TYPE_VALUE',
eventSeverity: ['LOW', 'HIGH']
},
updatedAt: {
gte: Date.now()
}
},
from: 0,
size: 50,
sort: [{ updatedAt: 'ASC' }]
});Initialize the builder once with Sequelize's Op, then call build() anywhere.
import { Op } from 'sequelize';
import QueryBuilder from '@webinmove/kuuliza';
QueryBuilder.init(Op);
const query = QueryBuilder.build({
filters: {
status: 'active',
createdAt: { gte: Date.now() }
},
sort: [{ createdAt: 'DESC' }],
from: 0,
size: 20
});
const results = await MyModel.findAll(query);| Field | Type | Required | Description |
|---|---|---|---|
filters |
object | no | Key/value pairs mapped to Sequelize where conditions |
sort |
array | no | Array of { field: 'ASC' | 'DESC' } objects |
from |
number | no | Offset (default: 0) |
size |
number | no | Limit (default: 100) |
attributes |
string[] | no | Columns to select |
Filters support the following operators as object keys:
eqne— equality / inequalitygtgteltlte— comparisonsinnotIn— array membershiplikenotLikeiLikenotILike— pattern matchingbetweennotBetween— rangeoverlap— array overlapisnot— null checks (use{ is: null }or{ not: null })or— OR condition
Nested objects (e.g. JSON columns) are supported — each key in the nested object is treated as a sub-filter.
build() returns a plain object ready to pass to any Sequelize finder:
{
attributes: undefined, // or string[]
where: { ... }, // Sequelize WhereOptions
order: [['field', 'ASC']] // or null
limit: 100,
offset: 0
}