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 1f710fb

Browse files
committedDec 10, 2014
Start documentation & travis ci
1 parent ecd2cd2 commit 1f710fb

File tree

12 files changed

+419
-0
lines changed

12 files changed

+419
-0
lines changed
 

‎.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ jsquery_gram.h
66
regression.diffs
77
regression.out
88
results
9+
*sw?

‎.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
before_script:
2+
- sudo su $USER -c ".travis/install"
3+
4+
script: sudo su $USER -c ".travis/test"
5+
6+
addons:
7+
postgresql: "9.3"
8+

‎.travis/install

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
3+
export ROOT=`pwd`
4+
export BUILD_DIR=/home/travis/build/pg
5+
export SOURCE_DIR=$BUILD_DIR/src
6+
7+
export PGDATA=$BUILD_DIR/data
8+
export PGPORT=5777
9+
export PGHOST=localhost
10+
11+
export PG_BIN=$BUILD_DIR/bin
12+
export PG_CONFIG=$BUILD_DIR
13+
14+
export PATH=$PATH:$PG_BIN
15+
16+
sudo apt-get -y -qq --purge remove postgresql libpq-dev libpq5 postgresql-client-common postgresql-common
17+
sudo apt-get -qq update
18+
sudo apt-get -qqy install \
19+
git \
20+
build-essential \
21+
gettext \
22+
libreadline6 \
23+
libreadline6-dev \
24+
zlib1g-dev \
25+
flex \
26+
bison \
27+
libxml2-dev \
28+
libxslt-dev
29+
30+
git clone -b REL9_4_STABLE --depth=1 git://git.postgresql.org/git/postgresql.git $SOURCE_DIR
31+
32+
# XML2_CONFIG=`which xml2-config` cd $SOURCE_DIR ./configure --prefix=$BUILD_DIR --with-libxml &&\
33+
34+
cd $SOURCE_DIR && ./configure --prefix=$BUILD_DIR && make && make install
35+
36+
37+
cd $ROOT && make USE_PGXS=1 && make install USE_PGXS=1
38+
39+
mkdir -p $PGDATA
40+
41+
$PG_BIN/initdb -D $PGDATA -E utf8
42+
43+
# echo "host all all 0.0.0.0/0 md5" >> $PGDATA/pg_hba.conf
44+
# echo "listen_addresses='*'" >> $PGDATA/postgresql.conf
45+
# echo "port=$PGPORT" >> $PGDATA/postgresql.conf
46+
47+
$PG_BIN/pg_ctl -D $PGDATA start

‎.travis/test

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
export BUILD_DIR=/home/travis/build/pg
4+
export SOURCE_DIR=$BUILD_DIR/src
5+
6+
export PGDATA=$BUILD_DIR/data
7+
export PGPORT=5777
8+
export PGHOST=localhost
9+
10+
export PG_BIN=$BUILD_DIR/bin
11+
export PG_CONFIG=$BUILD_DIR
12+
13+
export PATH=$PATH:$PG_BIN
14+
15+
export ROOT=`pwd`
16+
17+
make installcheck USE_PGXS=1

‎Dockerfile

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
FROM ubuntu:14.04
2+
MAINTAINER Nikolay Ryzhikov <niquola@gmail.com>
3+
4+
RUN apt-get -qq update
5+
RUN apt-get -qqy install git \
6+
build-essential \
7+
gettext \
8+
libreadline6 \
9+
libreadline6-dev \
10+
zlib1g-dev \
11+
flex \
12+
bison \
13+
libxml2-dev \
14+
libxslt-dev
15+
16+
RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && locale-gen
17+
18+
RUN useradd -m -s /bin/bash db && echo "db:db"|chpasswd && adduser db sudo
19+
RUN echo 'db ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
20+
21+
USER db
22+
ENV HOME /home/db
23+
ENV PG_BRANCH REL9_4_STABLE
24+
ENV PG_REPO git://git.postgresql.org/git/postgresql.git
25+
26+
RUN git clone -b $PG_BRANCH --depth=1 $PG_REPO $HOME/src
27+
RUN cd $HOME/src && ./configure --prefix=$HOME/bin && make && make install
28+
29+
ENV SOURCE_DIR $HOME/src
30+
31+
ENV PATH $HOME/bin/bin:$PATH
32+
ENV PGDATA $HOME/data
33+
ENV PGPORT 5432
34+
ENV PGHOST localhost
35+
RUN mkdir -p $PGDATA
36+
RUN initdb -D $PGDATA -E utf8
37+
38+
RUN echo "host all all 0.0.0.0/0 md5" >> $PGDATA/pg_hba.conf
39+
RUN echo "listen_addresses='*'" >> $PGDATA/postgresql.conf
40+
RUN echo "port=$PGPORT" >> $PGDATA/postgresql.conf
41+
42+
RUN pg_ctl -D $HOME/data -w start && psql postgres -c "alter user db with password 'db';"
43+
44+
RUN pg_ctl -D $HOME/data -w start && \
45+
cd $SOURCE_DIR/contrib/pgcrypto && \
46+
make && make install && make installcheck && \
47+
pg_ctl -w stop
48+
49+
RUN pg_ctl -D $HOME/data -w start && \
50+
cd $SOURCE_DIR/contrib && \
51+
git clone https://github.com/akorotkov/jsquery.git && \
52+
cd jsquery && make && make install && make installcheck && \
53+
pg_ctl -w stop
54+
55+
EXPOSE 5432
56+
CMD pg_ctl -D $HOME/data -w start && psql postgres

‎README.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# jsquery
2+
3+
[![Build Status](https://travis-ci.org/niquola/jsquery.svg)](https://travis-ci.org/niquola/jsquery)
4+
5+
`Jsquery` is PostgreSQL extension,
6+
which provides advanced query language for jsonb documents.
7+
8+
Features:
9+
10+
* recursive structure of query
11+
* search in array
12+
* rich set of comparison operators
13+
* types support
14+
* schema support (constraints on keys, values)
15+
* indexes support
16+
* hinting support
17+
18+
Jsquery implemented as datatype `jsquery` and operator `@@`.
19+
20+
Examples:
21+
22+
`#` - any element array
23+
24+
```SQL
25+
SELECT '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b.# = 2';
26+
```
27+
28+
`%` - any key
29+
30+
```SQL
31+
SELECT '{"a": {"b": [1,2,3]}}'::jsonb @@ '%.b.# = 2';
32+
```
33+
34+
`*` - anything
35+
36+
```SQL
37+
SELECT '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.# = 2';
38+
```
39+
40+
`$` - current element
41+
42+
```SQL
43+
select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b.# ($ = 2 OR $ < 3)';
44+
```
45+
46+
Use "double quotes" for key !
47+
48+
```SQL
49+
select 'a1."12222" < 111'::jsquery;
50+
```
51+
52+
## Documentation
53+
54+
* [Getting Started](doc/intro.md)
55+
* [Syntax](doc/syntax.md)
56+
* [Operators](doc/operators.md)
57+
* [Indexes](doc/indexes.md)
58+
* [Optimizer](doc/optimiser.md)
59+
60+
## Installation
61+
62+
Requirements:
63+
64+
* PostgreSQL >= 9.4
65+
66+
### Using pgxn.org ?
67+
68+
http://pgxn.org/
69+
70+
### Build from sources
71+
72+
```sh
73+
git clone https://github.com/akorotkov/jsquery.git $SOURCE_DIR/contrib
74+
cd $SOURCE_DIR/contrib/jsquery && make && make install && make installcheck
75+
76+
```
77+
78+
### Using docker
79+
80+
```
81+
docker run --name=myjsquery -p 5432:5555 -i -t jsquery/jsquery
82+
83+
psql -p 5555
84+
```
85+
86+
## Roadmap
87+
88+
* TODO1
89+
* TODO2
90+
91+
## Contribution
92+
93+
You can contribute by:
94+
95+
* stars
96+
* [issues](https://github.com/akorotkov/jsquery/issues)
97+
* documentation
98+
* pull requests
99+
100+
## License
101+
102+
MIT?

‎doc/indexes.md

Whitespace-only changes.

‎doc/intro.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Jsquery intro
2+
3+
```jsquery``` implemented as datatype and `@@` operator.
4+
5+
Search query has a form:
6+
7+
```SQL
8+
SELECT * FROM mytable
9+
WHERE jsonb_column @@ 'jsquery_expression';
10+
```
11+
12+
13+
```jsquery_expression``` usually consists
14+
of *path* and *value_expression*.
15+
16+
For example if we are looking for:
17+
18+
```json
19+
{
20+
"user": {
21+
"name": "Diego"
22+
},
23+
"site": {
24+
"url": "diego.com"
25+
}
26+
}
27+
```
28+
29+
the expresion is:
30+
31+
```
32+
user.name = 'diego'
33+
```
34+
35+
Sevral expressions could be connected using `AND` & `OR` operators:
36+
37+
```
38+
user.name = 'diego' AND site.url = 'diego.com'
39+
```

‎doc/jsquery.ebnf

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
result ::= ( expr | null)
2+
3+
array ::= '[' value_list ']'
4+
5+
scalar_value ::= (
6+
STRING_P
7+
| IN_P
8+
| IS_P
9+
| OR_P
10+
| AND_P
11+
| NOT_P
12+
| NULL_P
13+
| TRUE_P
14+
| ARRAY_T
15+
| FALSE_P
16+
| NUMERIC_T
17+
| OBJECT_T
18+
| STRING_T
19+
| BOOLEAN_T
20+
| NUMERIC_P )
21+
22+
value_list ::= (scalar_value | value_list ',' scalar_value)
23+
24+
right_expr ::= (
25+
'='right_exprscalar_value
26+
| IN_P '(' value_list ')'
27+
| '=' array
28+
| '=' '*'
29+
| '<' NUMERIC_P
30+
| '>' NUMERIC_P
31+
| '<' '=' NUMERIC_P
32+
| '>' '=' NUMERIC_P
33+
| '@' '>' array
34+
| '<' '@' array
35+
| '&' '&' array
36+
| IS_P ARRAY_T
37+
| IS_P NUMERIC_T
38+
| IS_P OBJECT_T
39+
| IS_P STRING_T
40+
| IS_P BOOLEAN_T )
41+
42+
expr ::= (
43+
path right_expr
44+
| path HINT_P right_expr
45+
| NOT_P expr
46+
| NOT_P HINT_P right_expr
47+
| NOT_P right_expr
48+
| path '(' expr ')'
49+
| '(' expr ')'
50+
| expr AND_P expr
51+
| expr OR_P expr)
52+
53+
key ::= (
54+
'*'
55+
| '#'
56+
| '%'
57+
| '$'
58+
| STRING_P
59+
| IN_P
60+
| IS_P
61+
| OR_P
62+
| AND_P
63+
| NULL_P
64+
| TRUE_P
65+
| ARRAY_T
66+
| FALSE_P
67+
| NUMERIC_T
68+
| OBJECT_T
69+
| STRING_T
70+
| BOOLEAN_T
71+
| NUMERIC_P )
72+
73+
key_any ::= ( key | NOT_P)
74+
75+
path ::= ( key | path '.' key_any | NOT_P '.' key_any )

‎doc/operators.md

Whitespace-only changes.

‎doc/optimizer.md

Whitespace-only changes.

‎doc/syntax.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
## Syntax
2+
3+
```jsquery``` expresion usually consists of *path* and *value_expression*:
4+
5+
```json
6+
{
7+
"user": {
8+
"name": "Diego"
9+
},
10+
"site": {
11+
"url": "diego.com"
12+
}
13+
}
14+
```
15+
16+
```
17+
user.name = 'diego'
18+
```
19+
20+
21+
```ebnf
22+
expr ::= path value_expr
23+
| path HINT value_expr
24+
| NOT expr
25+
| NOT HINT value_expr
26+
| NOT value_expr
27+
| path '(' expr ')'
28+
| '(' expr ')'
29+
| expr AND expr
30+
| expr OR expr
31+
32+
value_expr ::= '=' scalar_value
33+
| IN '(' value_list ')'
34+
| '=' array
35+
| '=' '*'
36+
| '<' NUMERIC
37+
| '<' '=' NUMERIC
38+
| '>' NUMERIC
39+
| '>' '=' NUMERIC
40+
| '@' '>' array
41+
| '<' '@' array
42+
| '&' '&' array
43+
| IS ARRAY
44+
| IS NUMERIC
45+
| IS OBJECT
46+
| IS STRING
47+
| IS BOOLEAN
48+
49+
path ::= key
50+
| path '.' key_any
51+
| NOT '.' key_any
52+
53+
key ::= '*'
54+
| '#'
55+
| '%'
56+
| '$'
57+
| STRING
58+
59+
key_any ::= key
60+
| NOT
61+
62+
value_list ::= scalar_value
63+
| value_list ',' scalar_value
64+
65+
array ::= '[' value_list ']'
66+
67+
scalar_value ::= null
68+
| STRING
69+
| true
70+
| false
71+
| NUMERIC
72+
| OBJECT
73+
```
74+

0 commit comments

Comments
 (0)
Please sign in to comment.