11
11
12
12
## Sample with not in
13
13
14
- Suppose you have a Web Service accessible using ` https://api.myserver.com/users ` and you want to create a filter to find
14
+ Suppose you have a Web Service accessible using ` https://api.myserver.com/users ` and want to create a filter to find
15
15
users not having a first name equals to ` Jack ` , ` Joe ` , ` Willian ` or ` Averell ` .
16
16
17
17
To do this you'll have to request your relationnal database with a ` not in ` SQL request. The ` php-value-filter-dsl `
@@ -43,6 +43,7 @@ $sqlFilter = $this->filterConverter->transform($urlParameterName, $urlParameterV
43
43
// Use the parsed result to build our SQL query
44
44
$preparedStatement = $pdo->prepare('select * from users where ' . $sqlFilter->getExpression());
45
45
46
+ // Bind our prepared statement parameters
46
47
$i = 1;
47
48
foreach($sqlFilter->getParams() as $param) {
48
49
$preparedStatement->bindParam($i++, $param);
@@ -57,12 +58,58 @@ prepared statement parameters `Jack`, `Joe`, `Willian`, `Averell`.
57
58
58
59
Very simple and useful, isn't it ?
59
60
60
- Please note that for now we only provide convertion of our filters into SQL, but will extend the library to provide
61
- additional converters to transform the filters into other formats.
61
+ Please note that for now we only provide convertion of filter expressions in SQL. Later we'll extend the library to
62
+ provide additional converters to transform the filters into other formats.
62
63
63
64
## Documentation
64
65
65
- In progress.
66
+ ### Standard operators
67
+
68
+ The expression language provides the following operators.
69
+
70
+ | Operator | ASCII value | Name | Value type(s) |
71
+ | ----------| -------------| --------------------------| ----------------------------------------|
72
+ | ` = ` | `%3D% | Equals | Integer, Float, String |
73
+ | ` < ` | ` %3C ` | Less than | Integer, Float |
74
+ | ` <= ` | ` %3C%3D ` | Less than or equal to | Integer, Float |
75
+ | ` > ` | ` %3E ` | Greater than | Integer, Float |
76
+ | ` >= ` | ` %3E%3D ` | Greater than or equal to | Integer, Float |
77
+ | ` in ` | | In | Integer list, Double list, String list |
78
+ | ` ~ ` | ` %7E% ` | Like | String |
79
+ | ` ! ` | | Not | _ see description above_ |
80
+
81
+ ### Not operator
82
+
83
+ The ` ! ` operator is special, it can be used directly before a value string or in combination with the ` = ` or ` in `
84
+ operators.
85
+
86
+ For exemple ` !5 ` or ` !=5 ` to express "no equals to 5" or ` !in('Paris','London') ` ro express "no equals to Paris or
87
+ London".
88
+
89
+ ### Like operator
90
+
91
+ The ` ~ ` operator allows to create like SQL requests, but it is always converted to expressions equals to
92
+ ` my_property like ? ` with a value equals to ` %word% ` which is not always wanted.
93
+
94
+ To express more complex like expressions you can use the ` * ` string operator in the value associated to the ` = ` or ` ~ `
95
+ operators.
96
+
97
+ For example ` property=~'*Nantes*France*' ` or ` property='Nantes*France*' ` will be translated to ` property like ? ` with
98
+ a parameter equals to ` %Nantes%France% ` .
99
+
100
+ ### Values
101
+
102
+ The following values can be used.
103
+
104
+ * ` null `
105
+ * ` true ` , converted to the string "true" if the associated property is a string, to 1 if the property is an integer and
106
+ to 1.0 if the property is a double
107
+ * ` false ` , converted to the string "false" if the associated property is a string, to 0 if the property is an integer
108
+ and to 0.0 if the property is a double
109
+ * integer
110
+ * floting number
111
+ * string (must be quoted with simple quotes ')
112
+ * string with an ISO 8601 format for the dates
66
113
67
114
## About Gomoob
68
115
0 commit comments