Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dot-build/query-builder
A general-purpose query builder to standarize search queries
https://github.com/dot-build/query-builder
Last synced: about 1 month ago
JSON representation
A general-purpose query builder to standarize search queries
- Host: GitHub
- URL: https://github.com/dot-build/query-builder
- Owner: dot-build
- Created: 2015-10-02T23:51:36.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-11-01T02:19:20.000Z (about 9 years ago)
- Last Synced: 2024-04-14T08:30:16.689Z (9 months ago)
- Language: JavaScript
- Size: 140 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## QueryBuilder
This is a generic search query builder. Its intent is to provide a standarized interface to build search queries, like those used in ORM systems or data layers like Hybernate, Doctrine or LINQ.
Its syntax can be extended to add custom operators while keeping the same interface idea. Besides the search parameters, there is also a set of methods to add pagination information and sorting fields.
## Built in operators
A query instance comes with these common operators:
`LT, LTE, GT, GTE, IN, EQ, NE, LK, ST, END`
The names are short versions of very common operations, such as `less than`, `less than or equal` and `like`.
## Production status
Not there yet.
## Sample code
```
var query = QueryBuilder.create().where('name').eq('john')
.where('age').gt(30)
.where('interests').in(['travel', 'food', 'sports']).skip(30) // skip first 30 results
.limit(20) // limit to 20 items.sort('name', true); // descending order
var search = query.toJSON();
console.log(search);
```The output looks like this:
```
{
"filters": [{
"name": "name",
"operator": "=",
"value": "john"
}, {
"name": "age",
"operator": ">",
"value": 30
}, {
"name": "interests",
"operator": "in",
"value": ["travel", "food", "sports"]
}],
"sorting": [
["name", "desc"]
],
"page": 1,
"skip": 30,
"limit": 20
}
```## Build
```
npm install
make install
make build
```