Skip to content

Commit 85c474a

Browse files
committed
documentation for templates, a lot of examples some fixes
1 parent 245e954 commit 85c474a

File tree

29 files changed

+924
-14
lines changed

29 files changed

+924
-14
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules/
2-
coverage/
2+
coverage/
3+
npm-debug.log

.npmignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
.npmignore
2-
test
1+
tests/
2+
examples/
3+
coverage/
4+
docs/
5+
gulpfile.js

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(The MIT License)
22

3-
Copyright (c) 2013-2014 Oleg Korobenko <oleg.korobenko@gmail.com>
3+
Copyright (c) 2013-2015 2do2go team <dev.2do2go@gmail.com>
44

55
Permission is hereby granted, free of charge, to any person obtaining
66
a copy of this software and associated documentation files (the

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,4 @@ $ gulp coverage
142142

143143
## License
144144

145-
MIT
145+
[MIT](./LICENSE)

docs/README.md

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,62 @@ Return object with properties:
5353
| `getValuesArray` | Method to get values as array.<br>Exists only if `separatedValues = true`. |
5454
| `getValuesObject` | Method to get values as object.<br>Exists only if `separatedValues = true`. |
5555

56-
## Queries
56+
## Query types
5757

5858
### select
5959

60-
__template:__ `{with} {withRecursive} select {distinct} {fields} from {from} {table} {query} {select} {expression} {alias} {join} {condition} {group} {sort} {limit} {offset}`
60+
Template for select queries.
6161

62+
__template:__ `{with} {withRecursive} select {distinct} {fields} from {table} {query} {select} {expression} {alias} {join} {condition} {group} {sort} {limit} {offset}`
63+
64+
### insert
65+
66+
Template for insert queries.
67+
68+
__template:__ `{with} {withRecursive} insert {or} into {table} {values} {condition} {returning}`
69+
70+
### update
71+
72+
Template for update queries.
73+
74+
__template:__ `{with} {withRecursive} update {or} {table} {modifier} {condition} {returning}`
75+
76+
### remove
77+
78+
Template for remove queries.
79+
80+
__template:__ `{with} {withRecursive} delete from {table} {condition} {returning}`
81+
82+
### union / intersect / except
83+
84+
Template for union, intersect and except queries.
85+
86+
__template:__ `{with} {withRecursive} {queries} {sort} {limit} {offset}`
87+
88+
### Auxiliary templates
89+
90+
Templates below are used inside of blocks:
91+
92+
### subQuery
93+
94+
Template is used to build subqueries.
95+
96+
__template:__ `({queryBody})`
97+
98+
### insertValues
99+
100+
Template is used by `values` block.
101+
102+
__template:__ `({fields}) values {fieldValues}`
103+
104+
### joinItem
105+
106+
Template is used by `join` block to build each item.
107+
108+
__template:__ `{type} join {table} {query} {select} {expression} {alias} {on}`
109+
110+
### withItem
111+
112+
Template is used by `with` and `withRecursive` blocks to build each item.
113+
114+
__template:__ `{name} {fields} as {query} {select} {expression}`

examples/common/condition.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Condition
2+
3+
## Example 1 - array
4+
5+
Query:
6+
7+
``` js
8+
var sql = jsonSql.build({
9+
table: 'table',
10+
condition: [
11+
{a: {$gt: 1}},
12+
{b: {$lt: 10}}
13+
]
14+
});
15+
```
16+
17+
Result:
18+
19+
``` js
20+
sql.query
21+
// select * from "table" where "a" > 1 and "b" < 10;
22+
23+
sql.values
24+
// {}
25+
```
26+
27+
## Example 2 - object
28+
29+
Query:
30+
31+
``` js
32+
var sql = jsonSql.build({
33+
table: 'table',
34+
condition: {
35+
a: {$gt: 1},
36+
b: {$lt: 10}
37+
}
38+
});
39+
```
40+
41+
Result:
42+
43+
``` js
44+
sql.query
45+
// select * from "table" where "a" > 1 and "b" < 10;
46+
47+
sql.values
48+
// {}
49+
```

examples/common/returning.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Returning
2+
3+
Query:
4+
5+
``` js
6+
var sql = jsonSql.build({
7+
type: 'insert',
8+
table: 'table',
9+
values: {a: 5},
10+
returning: ['table.*']
11+
});
12+
```
13+
14+
Result:
15+
16+
``` js
17+
sql.query
18+
// insert into "table" ("a") values (5) returning "table".*;
19+
20+
sql.values
21+
// {}
22+
```

examples/common/table.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Table
2+
3+
Query:
4+
5+
``` js
6+
var sql = jsonSql.build({
7+
table: 'table'
8+
});
9+
```
10+
11+
Result:
12+
13+
``` js
14+
sql.query
15+
// select * from "table";
16+
17+
sql.values
18+
// {}
19+
```

examples/common/with.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# With
2+
3+
## Example 1 - array
4+
5+
Query:
6+
7+
``` js
8+
var sql = jsonSql.build({
9+
'with': [{
10+
name: 'table',
11+
select: {table: 'withTable'}
12+
}],
13+
table: 'table'
14+
});
15+
```
16+
17+
Result:
18+
19+
``` js
20+
sql.query
21+
// with "table" as (select * from "withTable") select * from "table";
22+
23+
sql.values
24+
// {}
25+
```
26+
27+
28+
## Example 2 - object
29+
30+
Query:
31+
32+
``` js
33+
var sql = jsonSql.build({
34+
'with': {
35+
table: {
36+
select: {table: 'withTable'}
37+
}
38+
},
39+
table: 'table'
40+
});
41+
```
42+
43+
Result:
44+
45+
``` js
46+
sql.query
47+
// with "table" as (select * from "withTable") select * from "table";
48+
49+
sql.values
50+
// {}
51+
```

examples/common/withRecursive.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# With (recursive)
2+
3+
## Example 1 - array
4+
5+
Query:
6+
7+
``` js
8+
var sql = jsonSql.build({
9+
withRecursive: [{
10+
name: 'table',
11+
select: {table: 'withTable'}
12+
}],
13+
table: 'table'
14+
});
15+
```
16+
17+
Result:
18+
19+
``` js
20+
sql.query
21+
// with recursive "table" as (select * from "withTable") select * from "table";
22+
23+
sql.values
24+
// {}
25+
```
26+
27+
28+
## Example 2 - object
29+
30+
Query:
31+
32+
``` js
33+
var sql = jsonSql.build({
34+
withRecursive: {
35+
table: {
36+
select: {table: 'withTable'}
37+
}
38+
},
39+
table: 'table'
40+
});
41+
```
42+
43+
Result:
44+
45+
``` js
46+
sql.query
47+
// with recursive "table" as (select * from "withTable") select * from "table";
48+
49+
sql.values
50+
// {}
51+
```

0 commit comments

Comments
 (0)