Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

start docs#5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
niquola wants to merge4 commits intopostgrespro:master
base:master
Choose a base branch
Loading
fromniquola:master
Open
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
NextNext commit
Start documentation & travis ci
  • Loading branch information
@niquola
niquola committedDec 10, 2014
commit1f710fb2f1e45ac32962f1c35a7b9b5b7f66f056
1 change: 1 addition & 0 deletions.gitignore
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,3 +6,4 @@ jsquery_gram.h
regression.diffs
regression.out
results
*sw?
8 changes: 8 additions & 0 deletions.travis.yml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
before_script:
- sudo su $USER -c ".travis/install"

script: sudo su $USER -c ".travis/test"

addons:
postgresql: "9.3"

47 changes: 47 additions & 0 deletions.travis/install
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
#!/bin/bash

export ROOT=`pwd`
export BUILD_DIR=/home/travis/build/pg
export SOURCE_DIR=$BUILD_DIR/src

export PGDATA=$BUILD_DIR/data
export PGPORT=5777
export PGHOST=localhost

export PG_BIN=$BUILD_DIR/bin
export PG_CONFIG=$BUILD_DIR

export PATH=$PATH:$PG_BIN

sudo apt-get -y -qq --purge remove postgresql libpq-dev libpq5 postgresql-client-common postgresql-common
sudo apt-get -qq update
sudo apt-get -qqy install \
git \
build-essential \
gettext \
libreadline6 \
libreadline6-dev \
zlib1g-dev \
flex \
bison \
libxml2-dev \
libxslt-dev

git clone -b REL9_4_STABLE --depth=1 git://git.postgresql.org/git/postgresql.git $SOURCE_DIR

# XML2_CONFIG=`which xml2-config` cd $SOURCE_DIR ./configure --prefix=$BUILD_DIR --with-libxml &&\

cd $SOURCE_DIR && ./configure --prefix=$BUILD_DIR && make && make install


cd $ROOT && make USE_PGXS=1 && make install USE_PGXS=1

mkdir -p $PGDATA

$PG_BIN/initdb -D $PGDATA -E utf8

# echo "host all all 0.0.0.0/0 md5" >> $PGDATA/pg_hba.conf
# echo "listen_addresses='*'" >> $PGDATA/postgresql.conf
# echo "port=$PGPORT" >> $PGDATA/postgresql.conf

$PG_BIN/pg_ctl -D $PGDATA start
17 changes: 17 additions & 0 deletions.travis/test
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
#!/bin/bash

export BUILD_DIR=/home/travis/build/pg
export SOURCE_DIR=$BUILD_DIR/src

export PGDATA=$BUILD_DIR/data
export PGPORT=5777
export PGHOST=localhost

export PG_BIN=$BUILD_DIR/bin
export PG_CONFIG=$BUILD_DIR

export PATH=$PATH:$PG_BIN

export ROOT=`pwd`

make installcheck USE_PGXS=1
56 changes: 56 additions & 0 deletionsDockerfile
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
FROM ubuntu:14.04
MAINTAINER Nikolay Ryzhikov <niquola@gmail.com>

RUN apt-get -qq update
RUN apt-get -qqy install git \
build-essential \
gettext \
libreadline6 \
libreadline6-dev \
zlib1g-dev \
flex \
bison \
libxml2-dev \
libxslt-dev

RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && locale-gen

RUN useradd -m -s /bin/bash db && echo "db:db"|chpasswd && adduser db sudo
RUN echo 'db ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers

USER db
ENV HOME /home/db
ENV PG_BRANCH REL9_4_STABLE
ENV PG_REPO git://git.postgresql.org/git/postgresql.git

RUN git clone -b $PG_BRANCH --depth=1 $PG_REPO $HOME/src
RUN cd $HOME/src && ./configure --prefix=$HOME/bin && make && make install

ENV SOURCE_DIR $HOME/src

ENV PATH $HOME/bin/bin:$PATH
ENV PGDATA $HOME/data
ENV PGPORT 5432
ENV PGHOST localhost
RUN mkdir -p $PGDATA
RUN initdb -D $PGDATA -E utf8

RUN echo "host all all 0.0.0.0/0 md5" >> $PGDATA/pg_hba.conf
RUN echo "listen_addresses='*'" >> $PGDATA/postgresql.conf
RUN echo "port=$PGPORT" >> $PGDATA/postgresql.conf

RUN pg_ctl -D $HOME/data -w start && psql postgres -c "alter user db with password 'db';"

RUN pg_ctl -D $HOME/data -w start && \
cd $SOURCE_DIR/contrib/pgcrypto && \
make && make install && make installcheck && \
pg_ctl -w stop

RUN pg_ctl -D $HOME/data -w start && \
cd $SOURCE_DIR/contrib && \
git clone https://github.com/akorotkov/jsquery.git && \
cd jsquery && make && make install && make installcheck && \
pg_ctl -w stop

EXPOSE 5432
CMD pg_ctl -D $HOME/data -w start && psql postgres
102 changes: 102 additions & 0 deletionsREADME.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
# jsquery

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

`Jsquery` is PostgreSQL extension,
which provides advanced query language for jsonb documents.

Features:

* recursive structure of query
* search in array
* rich set of comparison operators
* types support
* schema support (constraints on keys, values)
* indexes support
* hinting support

Jsquery implemented as datatype `jsquery` and operator `@@`.

Examples:

`#` - any element array

```SQL
SELECT '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b.# = 2';
```

`%` - any key

```SQL
SELECT '{"a": {"b": [1,2,3]}}'::jsonb @@ '%.b.# = 2';
```

`*` - anything

```SQL
SELECT '{"a": {"b": [1,2,3]}}'::jsonb @@ '*.# = 2';
```

`$` - current element

```SQL
select '{"a": {"b": [1,2,3]}}'::jsonb @@ 'a.b.# ($ = 2 OR $ < 3)';
```

Use "double quotes" for key !

```SQL
select 'a1."12222" < 111'::jsquery;
```

## Documentation

* [Getting Started](doc/intro.md)
* [Syntax](doc/syntax.md)
* [Operators](doc/operators.md)
* [Indexes](doc/indexes.md)
* [Optimizer](doc/optimiser.md)

## Installation

Requirements:

* PostgreSQL >= 9.4

### Using pgxn.org ?

http://pgxn.org/

### Build from sources

```sh
git clone https://github.com/akorotkov/jsquery.git $SOURCE_DIR/contrib
cd $SOURCE_DIR/contrib/jsquery && make && make install && make installcheck

```

### Using docker

```
docker run --name=myjsquery -p 5432:5555 -i -t jsquery/jsquery

psql -p 5555
```

## Roadmap

* TODO1
* TODO2

## Contribution

You can contribute by:

* stars
* [issues](https://github.com/akorotkov/jsquery/issues)
* documentation
* pull requests

## License

MIT?
Empty file addeddoc/indexes.md
View file
Open in desktop
Empty file.
39 changes: 39 additions & 0 deletionsdoc/intro.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
# Jsquery intro

```jsquery``` implemented as datatype and `@@` operator.

Search query has a form:

```SQL
SELECT * FROM mytable
WHERE jsonb_column @@ 'jsquery_expression';
```


```jsquery_expression``` usually consists
of *path* and *value_expression*.

For example if we are looking for:

```json
{
"user": {
"name": "Diego"
},
"site": {
"url": "diego.com"
}
}
```

the expresion is:

```
user.name = 'diego'
```

Sevral expressions could be connected using `AND` & `OR` operators:

```
user.name = 'diego' AND site.url = 'diego.com'
```
75 changes: 75 additions & 0 deletionsdoc/jsquery.ebnf
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
result ::= ( expr | null)

array ::= '[' value_list ']'

scalar_value ::= (
STRING_P
| IN_P
| IS_P
| OR_P
| AND_P
| NOT_P
| NULL_P
| TRUE_P
| ARRAY_T
| FALSE_P
| NUMERIC_T
| OBJECT_T
| STRING_T
| BOOLEAN_T
| NUMERIC_P )

value_list ::= (scalar_value | value_list ',' scalar_value)

right_expr ::= (
'='right_exprscalar_value
| IN_P '(' value_list ')'
| '=' array
| '=' '*'
| '<' NUMERIC_P
| '>' NUMERIC_P
| '<' '=' NUMERIC_P
| '>' '=' NUMERIC_P
| '@' '>' array
| '<' '@' array
| '&' '&' array
| IS_P ARRAY_T
| IS_P NUMERIC_T
| IS_P OBJECT_T
| IS_P STRING_T
| IS_P BOOLEAN_T )

expr ::= (
path right_expr
| path HINT_P right_expr
| NOT_P expr
| NOT_P HINT_P right_expr
| NOT_P right_expr
| path '(' expr ')'
| '(' expr ')'
| expr AND_P expr
| expr OR_P expr)

key ::= (
'*'
| '#'
| '%'
| '$'
| STRING_P
| IN_P
| IS_P
| OR_P
| AND_P
| NULL_P
| TRUE_P
| ARRAY_T
| FALSE_P
| NUMERIC_T
| OBJECT_T
| STRING_T
| BOOLEAN_T
| NUMERIC_P )

key_any ::= ( key | NOT_P)

path ::= ( key | path '.' key_any | NOT_P '.' key_any )
Empty file addeddoc/operators.md
View file
Open in desktop
Empty file.
Empty file addeddoc/optimizer.md
View file
Open in desktop
Empty file.
Loading

[8]ページ先頭

©2009-2025 Movatter.jp