11<p align =" center " >
2- <img src =" logo.jpg " alt =" Ngx Guardian logo" width =" 200 " height =" 200 " >
2+ <img src =" https://raw.githubusercontent.com/rjlopezdev/typeorm-express-query-builder/master/ logo.jpg" alt =" TypeORM Express Query Builder logo" width =" 200 " height =" 200 " >
33</p >
44
55<h1 align =" center " > TypeORM Express Query Builder </h1 >
@@ -45,14 +45,12 @@ Use QueryBuilder export from package and pass your `req.query` as an argument:
4545``` typescript
4646import QueryBuilder from ' typeorm-express-query-builder' ;
4747
48- const builder = QueryBuilder (req .query );
48+ const builder = new QueryBuilder (req .query );
4949const builtQuery = builder .build ();
5050// Now your query is built, pass it to your TypeORM repository
5151const results = await fooRepository .find (builtQuery );
5252```
5353
54- ## Building queries from url
55-
5654Given the following url query string:
5755
5856` foo/?name__contains=foo&role__in=admin,common&age__gte=18&page=3&limit=10 `
@@ -71,25 +69,60 @@ It will be transformed into:
7169}
7270```
7371
72+ ## Different ways of retrieve data
73+
74+ ### GET, POST method by url query string
75+
76+ ` GET foo/?name__contains=foo&role__in=admin,common&age__gte=18&page=3&limit=10 `
77+
78+ ` POST foo/?name__contains=foo&role__in=admin,common&age__gte=18&page=3&limit=10 `
79+ ``` javascript
80+ app .get (' /foo' , (req , res ) => {
81+ const queryBuilder = new QueryBuilder (req .query ); // => Parsed into req.query
82+ const built = queryBuilder .build ();
83+ })
84+ ```
85+
86+ ### POST method by body
87+
88+ ``` javascript
89+ POST foo/ , body: {
90+ " name__contains" : " foo" ,
91+ " role__in" : " admin,common" ,
92+ " age__gte" : 18 ,
93+ " page" : 3 ,
94+ " limit" : 10
95+ }
96+ ```
97+
98+ ``` javascript
99+ app .post (' /foo' , (req , res ) => {
100+ const queryBuilder = new QueryBuilder (req .body ); // => Parsed into req.body
101+ const built = queryBuilder .build ();
102+ })
103+ ```
104+
74105## Available Lookups
75106
76107| Lookup | Behaviour | Example |
77108| --- | --- | --- |
78- _ (none)_ | Return entries that match with value | ` ?foo=raul `
79- __ contains__ | Return entries that contains value | ` ?foo__contains=lopez `
80- __ startswith__ | Return entries that starts with value | ` ?foo__startswith=r `
81- __ endswith__ | Return entries that ends with value | ` ?foo__endswith=dev `
82- __ isnull__ | Return entries with null value | ` ?foo__isnull `
83- __ lt__ | Return entries with value less than or equal to provided | ` ?foo__lt=18 `
84- __ lte__ | Return entries with value less than provided | ` ?foo__lte=18 `
85- __ gt__ | Returns entries with value greater tahn provided | ` ?foo__gt=18 `
86- __ gte__ | Return entries with value greater then or equal to provided | ` ?foo__gte=18 `
87- __ in__ | Return entries that match with values in list | ` ?foo__in=admin,common `
88- __ between__ | Return entries in range | ` ?foo__between=1,27 `
89-
90- ## Extra options
91-
92- | Option | Default | Behaviour |
93- | --- | :---: | --- |
94- page | __ 1__ | Entries page
95- limit | __ 25__ | Page size
109+ _ (none)_ | Return entries that match with value | ` foo=raul `
110+ __ contains__ | Return entries that contains value | ` foo__contains=lopez `
111+ __ startswith__ | Return entries that starts with value | ` foo__startswith=r `
112+ __ endswith__ | Return entries that ends with value | ` foo__endswith=dev `
113+ __ isnull__ | Return entries with null value | ` foo__isnull `
114+ __ lt__ | Return entries with value less than or equal to provided | ` foo__lt=18 `
115+ __ lte__ | Return entries with value less than provided | ` foo__lte=18 `
116+ __ gt__ | Returns entries with value greater than provided | ` foo__gt=18 `
117+ __ gte__ | Return entries with value greater than or equal to provided | ` foo__gte=18 `
118+ __ in__ | Return entries that match with values in list | ` foo__in=admin,common `
119+ __ between__ | Return entries in range | ` foo__between=1,27 `
120+
121+ ## Options
122+
123+ | Option | Default | Behaviour | Example |
124+ | --- | :---: | --- | --- |
125+ page | __ 1__ | Return entries for page ` page ` | ` page=2 `
126+ limit | __ 25__ | Return entries for page ` page ` paginated by size ` limit ` | ` limit=15 `
127+ order | - | Order for fields:<br >` + ` : Ascendant <br > ` - ` : Descendant | ` order=+foo,-name,+surname `
128+
0 commit comments