Skip to content

Commit 36ced7d

Browse files
author
Lucas Rocha
authored
Update README.md
1 parent 6e7d271 commit 36ced7d

File tree

1 file changed

+10
-63
lines changed

1 file changed

+10
-63
lines changed

README.md

Lines changed: 10 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ options = {
6363
```
6464
If the options are not provided, the default values will be used for the treatment of queries strings.
6565

66+
6667
### 2. Using custom configurations:
6768
```js
6869
const express = require('express')
@@ -72,7 +73,10 @@ const app = express()
7273
app.use(qs({
7374
use_page: true,
7475
client_db: 'mongodb',
75-
date_field: 'created_at'
76+
date_field: {
77+
start_at: 'timestamp',
78+
end_at: 'timestamp'
79+
}
7680
default: {
7781
fields: {name: 1 , age: 1, number: 1, _id: 0},
7882
sort: { created_at: 'desc' },
@@ -99,69 +103,12 @@ app.use(qs({
99103
*/
100104
```
101105

106+
For more details, access the [wiki](https://github.com/nutes-uepb/query-strings-parser/wiki/2.-Usage-Examples) page.
107+
102108
### 3. Supported Query Strings
103-
#### 3.1 Partial Answers
104-
| Query | Description | Result |
105-
| ------ | ------ | ------ |
106-
|`?fields=name,age`| Search where the user wants only the name and age of the user. |`{ fields: { name: 1, age: 1 } }` |
107-
108-
#### 3.2 Pagination
109-
**3.2.1 Pagination With Skip**
110-
111-
| Query | Description | Result |
112-
| ------ | ------ | ------ |
113-
| `?limit=10&skip=0` | Search where the user wants only 10 results, without skip any. | `{ pagination: { limit: 10, skip: 0 } }` |
114-
115-
**3.2.2 Pagination With page**
116-
117-
| Query | Description | Result |
118-
| ------ | ------ | ------ |
119-
| `?limit=10&page=2` | Search where the user wants results only 10 results, but the second page (in this case, from the 11th to the 20th result). | `{ pagination: { limit: 10, page: 2 } }` |
120-
121-
#### 3.3 Ordination
122-
| Query | Description | Result |
123-
| ------ | ------ | ------ |
124-
| `?sort=name,-age` | Search where the user wants results to be sorted in ascending order by name and in descending order by age. | `{ sort: { name: 'asc', age: 'desc' } }` |
125-
126-
#### 3.4 Filtering
127-
| Query | Description | Result |
128-
| ------ | ------ | ------ |
129-
| `?name=elvis&age=80` | Search where the user wants results that name equals elvis and age equals 80. | `{ filters: { name: 'elvis', age: 80 } }` |
130-
| `?name=elvis&name=john` | Search where the usar wants results that name equals elvis and john. | `{ filters: { $and: [ { name: 'elvis' }, { name: john } ] } }` |
131-
| `?name=elvis,john` | Search where the user wants results that name equals elvis or john. | `{ filters: { $or: [ { name: 'elvis' }, { name: john } ] } }` |
132-
| `?age=gt:30` | Search where the user wants results that age is greater than 30. | `{ filters: { age: { $gt: 30 } } }` |
133-
| `?age=gte:30` | Search where the user wants results that age is greater or equal than 30. | `{ filters: { age: { $gte: 30 } } }` |
134-
| `age=lt:30` | Search where the user wants results that age is lower than 30. | `{ filters: { age: { $lt: 30 } } }` |
135-
| `age=lte:30` | Search where the user wants results that age is lower or equal than 30. | `{ filters: { age: { $lte: 30 } } }` |
136-
137-
#### 3.5 Date
138-
| Query | Description | Result |
139-
| ------ | ------ | ------ |
140-
| `?start_at=2018-11-10&end_at=2018-12-10` | Search where the user wants results between 2018-12-10 and 2018-12-12. | `{ filters: { $and: [ { created_at: { $lt: '2018-12-10T23:59:59' } }, { created_at: { $gte: '2018-11-10T00:00:00' } } ] } }` |
141-
| `?start_at=2018-12-10` | Search where the user wants results between 2018-12-10 and the current date. In this example, the current day is: 2018-12-12. | `{ filters: { $and: [ { created_at: { $lt: '2018-12-13T23:59:59' } }, { created_at: { $gte: '2018-12-10T00:00:00' } } ] } }` |
142-
| `?end_at=2018-12-11&period=10d` | Search where the user wants results from 10 days before 2018-12-12. | `{ filters: { $and: [ { created_at: { $lt: '2018-12-11T23:59:59' } }, { created_at: { $gte: '2018-11-30T00:00:00' } } ] } }` |
143-
| `?period=10d` | Search where the user wants results from 10 days before the current date. In this example, the current day is: 2018-12-12. | `{ filters: { $and: [ { created_at: { $lt: '2018-12-13T23:59:59' } }, { created_at: { $gte: '2018-12-02T00:00:00' } } ] } }` |
144-
| `?end_at=2018-12-11&period=8w` | Search where the user wants results from 8 weeks before 2018-12-12. | `{ filters: { $and: [ { created_at: { $lt: '2018-12-11T23:59:59' } }, { created_at: { $gte: '2018-10-15T00:00:00' } } ] } }` |
145-
| `?period=8w` | Search where the user wants results from 8 weeks before the current date. In this example, the current day is: 2018-12-12. | `{ filters: { $and: [ { created_at: { $lt: '2018-12-13T23:59:59' } }, { created_at: { $gte: '2018-10-17T00:00:00' } } ] } }` |
146-
| `?end_at=2018-12-11&period=6m` | Search where the user wants results from 6 months before 2018-12-11. | `{ filters: { $and: [ { created_at: { $lt: '2018-12-11T23:59:59' } }, { created_at: { $gte: '2018-06-10T00:00:00' } } ] } }` |
147-
| `?period=6m` | Search where the user wants results from 6 months before the current date. In this example, the current day is: 2018-12-12. | `{ filters: { $and: [ { created_at: { $lt: '2018-12-13T23:59:59' } }, { created_at: { $gte: '2018-06-12T00:00:00' } } ] } }` |
148-
| `?end_at=2018-12-11&period=4y` | Search where the user wants results from 4 years before 2018-12-11. | `{ filters: { $and: [ { created_at: { $lt: '2018-12-11T23:59:59' } }, { created_at: { $gte: '2014-12-10T00:00:00' } } ] } }` |
149-
| `?period=4y` | Search where the user wants results from 4 years before the current date. In this example, the current day is: 2018-12-12. | `{ filters: { $and: [ { created_at: { $lt: '2018-12-13T23:59:59' } }, { created_at: { $gte: '2014-12-12T00:00:00' } } ] } }` |
150-
151-
#### 3.6 Search
152-
| Query | Description | Result |
153-
| ------ | ------ | ------ |
154-
| `?name=elvis*`| Search where the user want results that the name starts with value 'elvis'. | `{ filters: { name: { '$options': 'i', '$regex': '^elvis' } } ` |
155-
| `?name=*elvis` | Search where the user want results that the name ends with the value 'elvis'. | `{ filters: { name: { '$options': 'i', '$regex': 'elvis&' } } ` |
156-
| `?name=*elvis*` | Search where the user wants results for name that contains the value 'elvis' in any position. | `{ filters: { name: { '$options': 'i', '$regex': 'elvis' } } ` |
157-
158-
**NOTES** :
159-
* Default values are used only when they are not passed in the query string. For example, if you set the default value `?sort=-age` _(age in descending order)_ and your client makes a request with `?sort=name` _(name in ascending order)_, you will get in req.query the value `{ sort: { name: 'asc' } }`, since the values passed by the client will always have preference.
160-
* Remember to set whether you will use the page or not in the options. If you do not set this setting, it will work without page param, even if you pass the page setup on paging.
161-
* If you use custom configurations, the query configurations must be insert in json with name 'default'.
162-
* The accepted date format of Data params is yyyy-MM-dd or yyyy-MM-dd: hh: mm: ss. Any date outside this format will not work correctly.
163-
* The **date_field** parameter in the options is used in cases where you want to use filters with Date. If this value is not specified in the middleware configuration options, its default value will be 'created_at'.
164-
* The configurations that you don't set in middleware options it will be the default settings.
109+
110+
For informations and details about the supported query strings, access the [wiki](https://github.com/nutes-uepb/query-strings-parser/wiki/3.-Supported-Query-Strings) page.
111+
165112

166113
## Future Features
167114
- ¹Support for relational databases such as MySQL, PostgreSQL and SQLite.

0 commit comments

Comments
 (0)