PG Filters
A simple rust helper to generate postgres sql for pagination, sorting and filtering
Usage
let filters = new;
let sql = filters.sql;
assert_eq!;
Note
- filter rules are applied in the order which they are supplied
- sorting is applied after sorting on column name alphabetically (duplicates are removed)
- for readability on the first filtering rule you can use
where- anything other than AND/OR defaults to AND
Valid Filtering Options
The filtering accepts a filter operator and a conditional operator the valid options are below:
Filtering Operator
can be upper or lower case
- "="
- "!="
- ">"
- ">="
- "<"
- "<="
- "LIKE"
- "NOT LIKE"
- "IN"
- "NOT IN"
- "IS NULL"
- "IS NOT NULL"
- "STARTS WITH"
- "ENDS WITH"
Valid Conditional Filter Values
can be upper or lower case
- "AND"
- "OR"
Returned Objects
Along with the sql it also returns objects containing the pagination, sorting and filtering that has been applied e.g :
let pagination_sql = filters.pagination.sql
let pagination = filters.pagination.pagination
see the tests for more examples
Changelog
License
Licensed under either of these:
- MIT (https://opensource.org/licenses/MIT)
- Apache-2.0 (https://www.apache.org/licenses/LICENSE-2.0)