Added count parameter in GET /($entity) and POST /($entity)/searches

This commit is contained in:
Daniele Teti 2020-06-19 16:01:07 +02:00
parent 66c9a0f75d
commit 25a677bb40
2 changed files with 44 additions and 3 deletions

View File

@ -385,7 +385,8 @@ end;
- SSL Server support for `TMVCListener` (Thanks to [Sven Harazim](https://github.com/landrix))
- Improved! Datasets serialization speed improvement. In some case the performance [improves of 2 order of magnitude](https://github.com/danieleteti/delphimvcframework/issues/205#issuecomment-479513158). (Thanks to https://github.com/pedrooliveira01)
- New! Added `in` operator in RQL parser (Thank you to [João Antônio Duarte](https://github.com/joaoduarte19) for his initial work on this)
- New! Added `TMVCActiveRecord.Count<T>(RQL)` to count record based on RQL criteria
- New! Added `TMVCActiveRecord.Count<T>(RQL)` to count record based on RQL criteria.
- New! Added in `TMVCActiveRecordController` new `count` parameter. When in a "Get List" request is used a RQL filter, sending a "count=true" parameter, the response will contains also the count of the record matching filter.
- New! `TMVCActiveRecord` can handle non autogenerated primary key.
- New! Experimental (alpha stage) support for Android servers!
- New! Added support for `X-HTTP-Method-Override` to work behind corporate firewalls.
@ -1009,9 +1010,44 @@ begin
end;
```
#### RQL
Resource Query Language (RQL) is a query language designed for use in URIs with object style data structures. DMVCFramework supports RQL natively and the included MVCActiveRecord micro-framework, implement a large subset of the RQL specs.
RQL can be thought as basically a set of nestable named operators which each have a set of arguments. RQL is designed to have an extremely simple, but extensible grammar that can be written in a URL friendly query string. A simple RQL query with a single operator that indicates a search for any resources with a property of "foo" that has value of 5 could be written:
```SPARQL
eq(foo,5)
```
A more complex filter can include an arbitrary number of chained functions
```SPARQL
or(and(eq(name,"daniele"),eq(surname,"teti")),and(eq(name,"peter"),eq(surname,"parker"));sort(+name)
```
Which is translated (details depends from the RDBMS) in the following SQL.
```sql
select
name, surname {other fields}
from
people
where
(name = "daniele" and surname = "teti")
or
(name="peter" and surname = "parker")
order by
name asc
```
### RQL as Implemented by DMVCFramework
Here is a definition of the common operators (individual stores may have support for more less operators):
RQL is designed for modern application development. It is built for the web, ready for NoSQL, and highly extensible with simple syntax.
Here is a definition of the common operators as implemented in DMVCFramework' ActiveRecord:
```
eq(<property>,<value>) - Filters for objects where the specified property's value is equal to the provided value

View File

@ -153,10 +153,15 @@ begin
lInstance.Free;
end;
lResp := TMVCActiveRecordListResponse.Create(TMVCActiveRecord.SelectRQL(lARClassRef, lRQL,
GetMaxRecordCount), True);
try
lResp.Metadata.Add('count', lResp.Items.Count.ToString);
lResp.Metadata.Add('page_size', lResp.Items.Count.ToString);
if Context.Request.QueryStringParam('count').ToLower = 'true' then
begin
lResp.Metadata.Add('count', TMVCActiveRecord.Count(lARClassRef, lRQL).ToString);
end;
Render(lResp);
except
lResp.Free;