Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ivanceras/inquerest
url parameter parser for rest filter inquiry
https://github.com/ivanceras/inquerest
Last synced: 3 months ago
JSON representation
url parameter parser for rest filter inquiry
- Host: GitHub
- URL: https://github.com/ivanceras/inquerest
- Owner: ivanceras
- License: mit
- Created: 2015-11-06T21:39:36.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2020-08-07T12:05:09.000Z (over 4 years ago)
- Last Synced: 2024-05-23T07:54:41.036Z (8 months ago)
- Language: Rust
- Homepage:
- Size: 671 KB
- Stars: 25
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-rust-cn - ivanceras/inquerest - ci.org/ivanceras/inquerest.svg?branch=master)](https://travis-ci.org/ivanceras/inquerest) (Libraries / Parsing)
- awesome-rust - ivanceras/inquerest - ci.org/ivanceras/inquerest.svg?branch=master)](https://travis-ci.org/ivanceras/inquerest) (Libraries / Parsing)
- awesome-rust-zh - ivanceras/inquerest - 用于 REST 过滤器查询的 URL 参数解析器[![Build Status](https://api.travis-ci.org/ivanceras/inquerest.svg?branch=master)](https://travis-ci.org/ivanceras/inquerest) (库 / 解析)
README
# inquerest
Inquerest can parse complex url query into a SQL abstract syntax tree.
Example this url:
```rust
/person?age=lt.42&(student=eq.true|gender=eq.'M')&group_by=sum(age),grade,gender&having=min(age)=gt.42&order_by=age.desc,height.asc&page=20&page_size=100
```
will be parsed into:```rust
Select {
from_table: FromTable {
from: Table {
name: "person",
},
join: None,
},
filter: Some(
BinaryOperation(
BinaryOperation {
left: BinaryOperation(
BinaryOperation {
left: Column(
Column {
name: "age",
},
),
operator: Lt,
right: Value(
Number(
42.0,
),
),
},
),
operator: And,
right: Nested(
BinaryOperation(
BinaryOperation {
left: BinaryOperation(
BinaryOperation {
left: Column(
Column {
name: "student",
},
),
operator: Eq,
right: Value(
Bool(
true,
),
),
},
),
operator: Or,
right: BinaryOperation(
BinaryOperation {
left: Column(
Column {
name: "gender",
},
),
operator: Eq,
right: Value(
String(
"M",
),
),
},
),
},
),
),
},
),
),
group_by: Some(
[
Function(
Function {
name: "sum",
params: [
Column(
Column {
name: "age",
},
),
],
},
),
Column(
Column {
name: "grade",
},
),
Column(
Column {
name: "gender",
},
),
],
),
having: Some(
BinaryOperation(
BinaryOperation {
left: Function(
Function {
name: "min",
params: [
Column(
Column {
name: "age",
},
),
],
},
),
operator: Gt,
right: Value(
Number(
42.0,
),
),
},
),
),
projection: None,
order_by: Some(
[
Order {
expr: Column(
Column {
name: "age",
},
),
direction: Some(
Desc,
),
},
Order {
expr: Column(
Column {
name: "height",
},
),
direction: Some(
Asc,
),
},
],
),
range: Some(
Page(
Page {
page: 20,
page_size: 100,
},
),
),
}
```
Which translate to the sql statement:
```sql
SELECT * FROM person WHERE age < 42 AND (student = true OR gender = 'M') GROUP BY sum(age), grade, gender HAVING min(age) > 42 ORDER BY age DESC, height ASC LIMIT 100 OFFSET 1900 ROWS
```
Note: However, you don't want to convert to the sql statement directly to avoid sql injection
attack. You need to validate the tables and columns if it is allowed to be accessed by the
user. You also need to extract the values yourself and supply it as a parameterized value into
your ORM.##### Please support this project:
[![Become a patron](https://c5.patreon.com/external/logo/become_a_patron_button.png)](https://www.patreon.com/ivanceras)License: MIT