1
- Python RQL
2
- ==========
1
+ # Python RQL
2
+
3
+
3
4
[ ![ pyversions] ( https://img.shields.io/pypi/pyversions/lib-rql.svg )] ( https://pypi.org/project/lib-rql/ )
4
5
[ ![ PyPi Status] ( https://img.shields.io/pypi/v/lib-rql.svg )] ( https://pypi.org/project/lib-rql/ )
5
6
[ ![ PyPI status] ( https://img.shields.io/pypi/status/lib-rql.svg )] ( https://pypi.org/project/lib-rql/ )
7
+ [ ![ PyPI Downloads] ( https://img.shields.io/pypi/dm/lib-rql )] ( https://pypi.org/project/lib-rql/ )
6
8
[ ![ Quality Gate Status] ( https://sonarcloud.io/api/project_badges/measure?project=lib-rql&metric=alert_status )] ( https://sonarcloud.io/summary/new_code?id=lib-rql )
7
9
[ ![ Coverage] ( https://sonarcloud.io/api/project_badges/measure?project=lib-rql&metric=coverage )] ( https://sonarcloud.io/summary/new_code?id=lib-rql )
8
10
9
- RQL
10
- ---
11
+
12
+
13
+ ## Introduction
11
14
12
15
RQL (Resource query language) is designed for modern application development. It is built for the web, ready for NoSQL, and highly extensible with simple syntax.
13
16
This is a query language fast and convenient database interaction. RQL was designed for use in URLs to request object-style data structures.
14
17
15
18
[ RQL Reference] ( https://connect.cloudblue.com/community/api/rql/ )
16
19
17
- Notes
18
- -----
20
+ ## Install
21
+
22
+ ` Python RQL ` can be installed from [ pypi.org] ( https://pypi.org/project/lib-rql/ ) using pip:
23
+
24
+ ```
25
+ $ pip install lib-rql
26
+ ```
27
+
28
+ ## Documentation
29
+
30
+ [ ` Python RQL ` documentation] ( https://lib-rql.readthedocs.io/en/latest/ ) is hosted on the _ Read the Docs_ service.
31
+
32
+
33
+ ## Projects using Python RQL
34
+
35
+ ` Django RQL ` is the Django app, that adds RQL filtering to your application.
36
+
37
+ Visit the [ Django RQL] ( https://github.com/cloudblue/django-rql ) project repository for more informations.
38
+
39
+
40
+ ## Notes
19
41
20
42
Parsing is done with [ Lark] ( https://github.com/lark-parser/lark ) ([ cheatsheet] ( https://lark-parser.readthedocs.io/en/latest/lark_cheatsheet.pdf ) ).
21
43
The current parsing algorithm is [ LALR(1)] ( https://www.wikiwand.com/en/LALR_parser ) with standard lexer.
22
44
23
- Supported operators
24
- =============================
45
+ 0 . Values with whitespaces or special characters, like ',' need to have "" or ''
46
+ 1 . Supported date format is ISO8601: 2019-02-12
47
+ 2 . Supported datetime format is ISO8601: 2019-02-12T10:02:00 / 2019-02-12T10:02Z / 2019-02-12T10:02:00+03:00
48
+
49
+
50
+ ## Supported operators
51
+
25
52
1 . Comparison (eq, ne, gt, ge, lt, le, like, ilike, search)
26
53
2 . List (in, out)
27
54
3 . Logical (and, or, not)
@@ -31,8 +58,11 @@ Supported operators
31
58
7 . Tuple (t)
32
59
33
60
34
- Example
35
- =======
61
+ ## Examples
62
+
63
+ ### Parsing a RQL query
64
+
65
+
36
66
``` python
37
67
from py_rql import parse
38
68
from py_rql.exceptions import RQLFilterError
@@ -43,27 +73,66 @@ except RQLFilterError:
43
73
pass
44
74
```
45
75
46
- Notes
47
- =====
48
- 0 . Values with whitespaces or special characters, like ',' need to have "" or ''
49
- 1 . Supported date format is ISO8601: 2019-02-12
50
- 2 . Supported datetime format is ISO8601: 2019-02-12T10:02:00 / 2019-02-12T10:02Z / 2019-02-12T10:02:00+03:00
76
+
77
+ ### Filter a list of dictionaries
78
+
79
+ ``` python
80
+ from py_rql.constants import FilterTypes
81
+ from py_rql.filter_cls import FilterClass
82
+
83
+
84
+ class BookFilter (FilterClass ):
85
+ FILTERS = [
86
+ {
87
+ ' filter' : ' title' ,
88
+ },
89
+ {
90
+ ' filter' : ' author.name' ,
91
+ },
92
+ {
93
+ ' filter' : ' status' ,
94
+ },
95
+ {
96
+ ' filter' : ' pages' ,
97
+ ' type' : FilterTypes.INT ,
98
+ },
99
+ {
100
+ ' filter' : ' featured' ,
101
+ ' type' : FilterTypes.BOOLEAN ,
102
+ },
103
+ {
104
+ ' filter' : ' publish_date' ,
105
+ ' type' : FilterTypes.DATETIME ,
106
+ },
107
+ ]
108
+
109
+ filters = BookFilter()
110
+
111
+ query = ' eq(title,Practical Modern JavaScript)'
112
+ results = list (filters.filter(query, DATA ))
113
+
114
+ print (results)
115
+
116
+ query = ' or(eq(pages,472),lt(pages,400))'
117
+ results = list (filters.filter(query, DATA ))
118
+
119
+ print (results)
120
+ ```
51
121
52
122
53
- Development
54
- ===========
123
+ ## Development
124
+
55
125
56
126
1 . Python 3.6+
57
- 0 . Install dependencies ` requirements/dev.txt `
127
+ 0 . Install dependencies ` pip install poetry && poetry install `
58
128
59
- Testing
60
- =======
129
+ ## Testing
61
130
62
131
1 . Python 3.6+
63
- 0 . Install dependencies ` requirements/test.txt `
132
+ 0 . Install dependencies ` pip install poetry && poetry install `
64
133
65
- Check code style: ` flake8 `
66
- Run tests: ` pytest `
134
+ Check code style: ` poetry run flake8`
135
+ Run tests: ` poetry run pytest`
67
136
68
137
Tests reports are generated in ` tests/reports ` .
69
138
* ` out.xml ` - JUnit test results
@@ -72,3 +141,6 @@ Tests reports are generated in `tests/reports`.
72
141
To generate HTML coverage reports use:
73
142
` --cov-report html:tests/reports/cov_html `
74
143
144
+ ## License
145
+
146
+ ` Python RQL ` is released under the [ Apache License Version 2.0] ( https://www.apache.org/licenses/LICENSE-2.0 ) .
0 commit comments