Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e5766ce

Browse files
committedDec 25, 2014
update readme
1 parent b9c5779 commit e5766ce

File tree

2 files changed

+90
-5
lines changed

2 files changed

+90
-5
lines changed
 

‎README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[![Build Status](https://travis-ci.org/niquola/jsquery.svg)](https://travis-ci.org/niquola/jsquery)
44

5+
56
`Jsquery` is PostgreSQL extension,
67
which provides advanced query language for jsonb documents.
78

@@ -15,6 +16,7 @@ Features:
1516
* indexes support
1617
* hinting support
1718

19+
1820
Jsquery implemented as datatype `jsquery` and operator `@@`.
1921

2022
Examples:
@@ -51,9 +53,7 @@ select 'a1."12222" < 111'::jsquery;
5153

5254
## Documentation
5355

54-
* [Getting Started](doc/intro.md)
55-
* [Syntax](doc/syntax.md)
56-
* [Operators](doc/operators.md)
56+
* [Syntax](doc/intro.md)
5757
* [Indexes](doc/indexes.md)
5858
* [Optimizer](doc/optimiser.md)
5959

‎doc/intro.md

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,99 @@ For example if we are looking for:
2626
}
2727
```
2828

29-
the expresion is:
29+
the expression is:
3030

3131
```
3232
user.name = 'diego'
3333
```
3434

35-
Sevral expressions could be connected using `AND` & `OR` operators:
35+
Sevral expressions could be connected using boolean `AND` & `OR` operators:
3636

3737
```
3838
user.name = 'diego' AND site.url = 'diego.com'
3939
```
40+
41+
Expression could be negated with `NOT` operator:
42+
43+
```
44+
NOT user.name = 'diego'
45+
```
46+
47+
JSON value could be one following types:
48+
49+
* array
50+
* numeric
51+
* object
52+
* string
53+
* boolean
54+
55+
You can check type using `is` operator:
56+
57+
```
58+
user.name is array
59+
user.name is numeric
60+
user.name is object
61+
user.name is string
62+
user.name is boolean
63+
```
64+
65+
For all types you `=` (equality) operator is defined:
66+
67+
```
68+
user.roles = ["admin","root"]
69+
user.age = 3
70+
user.active = true
71+
user.address = {city: "SPb"}
72+
user.name = "diego"
73+
```
74+
75+
For numerics there are expected comparison operators:
76+
77+
```
78+
x > 1 AND x < 10
79+
x >= 1 AND x <= 10
80+
```
81+
82+
To check that scalar value belongs to some list:
83+
84+
```sql
85+
select '{a: 2}'::jsonb @@ 'a IN (1,2,5)';
86+
```
87+
88+
For arrays there are convenient operators:
89+
90+
```sql
91+
-- overlap
92+
select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b && [1,2,5]';
93+
94+
-- contains
95+
select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b @> [1,2]';
96+
97+
-- contained
98+
select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b <@ [1,2,3,4,5]'
99+
```
100+
101+
If you just want to check that some path exists in json document use `=*`:
102+
103+
select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b = *'
104+
105+
106+
Path expression supports wild cards:
107+
108+
`#` - any alement of array
109+
`%` - any key in object
110+
`*` - any path
111+
112+
```sql
113+
select '{a: {b: {c: 1}}}'::jsonb @@ '*.c = 1'
114+
select '{a: {b: {c: 1}}}'::jsonb @@ 'a.%.c = 1'
115+
select '{a: {b: [1,2]}}'::jsonb @@ 'a.b.# = 1'
116+
```
117+
118+
jsquery expression could be expressed recursively using `()`:
119+
120+
```
121+
address(city = "SPB" AND street = "Nevskiy")
122+
```
123+
124+
This means eval `city = "SPB" AND street = "Nevskiy"` expression in context of `address` attribute.

0 commit comments

Comments
 (0)
Please sign in to comment.