sql-tools 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -22
- package/README.md +120 -120
- package/bin/sql-tools.js +3 -10
- package/package.json +11 -6
package/LICENSE
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2015 Codenautas
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
22
|
-
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015 Codenautas
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
CHANGED
|
@@ -1,121 +1,121 @@
|
|
|
1
|
-
# sql-tools
|
|
2
|
-
olap for sql non-olap engines / and other tools
|
|
3
|
-
<!--multilang v0 en:README.md es:LEEME.md -->
|
|
4
|
-
|
|
5
|
-
<!--lang:es--]
|
|
6
|
-
|
|
7
|
-
OLAP y otras herramientas para motores de base de datos SQL que no tienen OLAP
|
|
8
|
-
|
|
9
|
-
[!--lang:*-->
|
|
10
|
-
|
|
11
|
-

|
|
12
|
-
[](https://npmjs.org/package/sql-tools)
|
|
13
|
-
[](https://npmjs.org/package/sql-tools)
|
|
14
|
-
[](https://travis-ci.org/codenautas/sql-tools)
|
|
15
|
-
[](https://coveralls.io/r/codenautas/sql-tools)
|
|
16
|
-
[](https://codeclimate.com/github/codenautas/sql-tools)
|
|
17
|
-
[](https://david-dm.org/codenautas/sql-tools)
|
|
18
|
-
|
|
19
|
-
<!--multilang buttons-->
|
|
20
|
-
|
|
21
|
-
language: 
|
|
22
|
-
also available in:
|
|
23
|
-
[](LEEME.md)
|
|
24
|
-
|
|
25
|
-
<!--lang:en-->
|
|
26
|
-
|
|
27
|
-
## Install
|
|
28
|
-
|
|
29
|
-
<!--lang:es--]
|
|
30
|
-
## Instalación
|
|
31
|
-
|
|
32
|
-
[!--lang:*-->
|
|
33
|
-
|
|
34
|
-
```sh
|
|
35
|
-
$ npm install sql-tools
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
<!--lang:en-->
|
|
39
|
-
|
|
40
|
-
## Main goal
|
|
41
|
-
|
|
42
|
-
Transfor a SQL sentence in a SQL with totals.
|
|
43
|
-
|
|
44
|
-
<!--lang:es--]
|
|
45
|
-
|
|
46
|
-
## Objetivo principal
|
|
47
|
-
|
|
48
|
-
Transformar una sentencia SQL en otra que obtenga también los totales agrupando por la variable especificada.
|
|
49
|
-
|
|
50
|
-
[!--lang:en-->
|
|
51
|
-
|
|
52
|
-
## Definitions
|
|
53
|
-
|
|
54
|
-
Uses a list of field definition with the form:
|
|
55
|
-
|
|
56
|
-
attribute | mandatory | use
|
|
57
|
-
----------|-----------|-------------------------------------
|
|
58
|
-
name | yes | name of the field in the database
|
|
59
|
-
place | yes | 'data' if must be added, 'left' or 'top' if it must apear in the GROUP BY clausule
|
|
60
|
-
aggLabel | for pivot | text to insert in the added rows
|
|
61
|
-
aggExp | no | the expression when is different to SUM(x)
|
|
62
|
-
|
|
63
|
-
<!--lang:es--]
|
|
64
|
-
|
|
65
|
-
## Definición
|
|
66
|
-
|
|
67
|
-
Usa una lista de definición de campos con los siguientes atributos:
|
|
68
|
-
|
|
69
|
-
atributo | obligatorio | uso
|
|
70
|
-
----------|-----------|-------------------------------------
|
|
71
|
-
name | sí | nombre del campo
|
|
72
|
-
place | sí | 'data' si el campo debe agregarse, 'left' o 'top' si debe pertenecer a la cláusula GROUP BY
|
|
73
|
-
aggLabel | p/pivote | el texto que debe ponerse en las filas de datos agregados
|
|
74
|
-
aggExp | no | la expresión de totalización cuando no es SUM(x)
|
|
75
|
-
|
|
76
|
-
[!--lang:en-->
|
|
77
|
-
|
|
78
|
-
## Example
|
|
79
|
-
|
|
80
|
-
<!--lang:es--]
|
|
81
|
-
|
|
82
|
-
## Ejemplo
|
|
83
|
-
|
|
84
|
-
[!--lang:*-->
|
|
85
|
-
|
|
86
|
-
```js
|
|
87
|
-
var olap = require('sql-tools').olap;
|
|
88
|
-
|
|
89
|
-
var varsDef=[
|
|
90
|
-
{name: "zone", place:"left", aggLabel:"=SUM="},
|
|
91
|
-
{name: "kind", place:"left"},
|
|
92
|
-
{name: "sales", place:"data"},
|
|
93
|
-
{name: "calif", place:"data", aggExp:"min(calif)"}
|
|
94
|
-
];
|
|
95
|
-
|
|
96
|
-
var sql_total=olap.cube("select * from sales", 'zone', varsDef);
|
|
97
|
-
|
|
98
|
-
console.log(sql_total);
|
|
99
|
-
/*
|
|
100
|
-
WITH "olap cube" AS (
|
|
101
|
-
select * from sales
|
|
102
|
-
) SELECT * FROM "olap cube"
|
|
103
|
-
UNION SELECT '=SUM=', kind, SUM(sales), min(calif)
|
|
104
|
-
FROM "olap cube"
|
|
105
|
-
GROUP BY kind
|
|
106
|
-
*/
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
<!--lang:en-->
|
|
110
|
-
|
|
111
|
-
## License
|
|
112
|
-
|
|
113
|
-
<!--lang:es--]
|
|
114
|
-
|
|
115
|
-
## Licencia
|
|
116
|
-
|
|
117
|
-
[!--lang:*-->
|
|
118
|
-
|
|
119
|
-
[MIT](LICENSE)
|
|
120
|
-
|
|
1
|
+
# sql-tools
|
|
2
|
+
olap for sql non-olap engines / and other tools
|
|
3
|
+
<!--multilang v0 en:README.md es:LEEME.md -->
|
|
4
|
+
|
|
5
|
+
<!--lang:es--]
|
|
6
|
+
|
|
7
|
+
OLAP y otras herramientas para motores de base de datos SQL que no tienen OLAP
|
|
8
|
+
|
|
9
|
+
[!--lang:*-->
|
|
10
|
+
|
|
11
|
+

|
|
12
|
+
[](https://npmjs.org/package/sql-tools)
|
|
13
|
+
[](https://npmjs.org/package/sql-tools)
|
|
14
|
+
[](https://travis-ci.org/codenautas/sql-tools)
|
|
15
|
+
[](https://coveralls.io/r/codenautas/sql-tools)
|
|
16
|
+
[](https://codeclimate.com/github/codenautas/sql-tools)
|
|
17
|
+
[](https://david-dm.org/codenautas/sql-tools)
|
|
18
|
+
|
|
19
|
+
<!--multilang buttons-->
|
|
20
|
+
|
|
21
|
+
language: 
|
|
22
|
+
also available in:
|
|
23
|
+
[](LEEME.md)
|
|
24
|
+
|
|
25
|
+
<!--lang:en-->
|
|
26
|
+
|
|
27
|
+
## Install
|
|
28
|
+
|
|
29
|
+
<!--lang:es--]
|
|
30
|
+
## Instalación
|
|
31
|
+
|
|
32
|
+
[!--lang:*-->
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
$ npm install sql-tools
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
<!--lang:en-->
|
|
39
|
+
|
|
40
|
+
## Main goal
|
|
41
|
+
|
|
42
|
+
Transfor a SQL sentence in a SQL with totals.
|
|
43
|
+
|
|
44
|
+
<!--lang:es--]
|
|
45
|
+
|
|
46
|
+
## Objetivo principal
|
|
47
|
+
|
|
48
|
+
Transformar una sentencia SQL en otra que obtenga también los totales agrupando por la variable especificada.
|
|
49
|
+
|
|
50
|
+
[!--lang:en-->
|
|
51
|
+
|
|
52
|
+
## Definitions
|
|
53
|
+
|
|
54
|
+
Uses a list of field definition with the form:
|
|
55
|
+
|
|
56
|
+
attribute | mandatory | use
|
|
57
|
+
----------|-----------|-------------------------------------
|
|
58
|
+
name | yes | name of the field in the database
|
|
59
|
+
place | yes | 'data' if must be added, 'left' or 'top' if it must apear in the GROUP BY clausule
|
|
60
|
+
aggLabel | for pivot | text to insert in the added rows
|
|
61
|
+
aggExp | no | the expression when is different to SUM(x)
|
|
62
|
+
|
|
63
|
+
<!--lang:es--]
|
|
64
|
+
|
|
65
|
+
## Definición
|
|
66
|
+
|
|
67
|
+
Usa una lista de definición de campos con los siguientes atributos:
|
|
68
|
+
|
|
69
|
+
atributo | obligatorio | uso
|
|
70
|
+
----------|-----------|-------------------------------------
|
|
71
|
+
name | sí | nombre del campo
|
|
72
|
+
place | sí | 'data' si el campo debe agregarse, 'left' o 'top' si debe pertenecer a la cláusula GROUP BY
|
|
73
|
+
aggLabel | p/pivote | el texto que debe ponerse en las filas de datos agregados
|
|
74
|
+
aggExp | no | la expresión de totalización cuando no es SUM(x)
|
|
75
|
+
|
|
76
|
+
[!--lang:en-->
|
|
77
|
+
|
|
78
|
+
## Example
|
|
79
|
+
|
|
80
|
+
<!--lang:es--]
|
|
81
|
+
|
|
82
|
+
## Ejemplo
|
|
83
|
+
|
|
84
|
+
[!--lang:*-->
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
var olap = require('sql-tools').olap;
|
|
88
|
+
|
|
89
|
+
var varsDef=[
|
|
90
|
+
{name: "zone", place:"left", aggLabel:"=SUM="},
|
|
91
|
+
{name: "kind", place:"left"},
|
|
92
|
+
{name: "sales", place:"data"},
|
|
93
|
+
{name: "calif", place:"data", aggExp:"min(calif)"}
|
|
94
|
+
];
|
|
95
|
+
|
|
96
|
+
var sql_total=olap.cube("select * from sales", 'zone', varsDef);
|
|
97
|
+
|
|
98
|
+
console.log(sql_total);
|
|
99
|
+
/*
|
|
100
|
+
WITH "olap cube" AS (
|
|
101
|
+
select * from sales
|
|
102
|
+
) SELECT * FROM "olap cube"
|
|
103
|
+
UNION SELECT '=SUM=', kind, SUM(sales), min(calif)
|
|
104
|
+
FROM "olap cube"
|
|
105
|
+
GROUP BY kind
|
|
106
|
+
*/
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
<!--lang:en-->
|
|
110
|
+
|
|
111
|
+
## License
|
|
112
|
+
|
|
113
|
+
<!--lang:es--]
|
|
114
|
+
|
|
115
|
+
## Licencia
|
|
116
|
+
|
|
117
|
+
[!--lang:*-->
|
|
118
|
+
|
|
119
|
+
[MIT](LICENSE)
|
|
120
|
+
|
|
121
121
|
.............................
|
package/bin/sql-tools.js
CHANGED
|
@@ -171,16 +171,9 @@ SqlTools.structuredData.sqlsDeletes = function sqlsDeletes(data, structuredData,
|
|
|
171
171
|
(data[childTable.tableName]||[]).forEach(function(childData){
|
|
172
172
|
queriesArray = SqlTools.structuredData.sqlsDeletes(childData, childTable, queriesArray, childPksIndex);
|
|
173
173
|
});
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
queriesArray.push(
|
|
178
|
-
"delete from " + SqlTools.quoteIdent(childTable.tableName) +
|
|
179
|
-
" where " + conditionChild.join(' and ') +
|
|
180
|
-
" and " + join1wp(parentPk) + `
|
|
181
|
-
not in (select ${parentPk.join(', ')} from jsonb_populate_recordset(null::${SqlTools.quoteIdent(childTable.tableName)},
|
|
182
|
-
${SqlTools.quoteLiteral(JSON.stringify(data[childTable.tableName]))}::jsonb
|
|
183
|
-
));`
|
|
174
|
+
queriesArray.push(`
|
|
175
|
+
delete from ${SqlTools.quoteIdent(childTable.tableName)}
|
|
176
|
+
where ${conditionChild.join(' and ')}`
|
|
184
177
|
);
|
|
185
178
|
});
|
|
186
179
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sql-tools",
|
|
3
3
|
"description": "olap for sql non-olap engines / and other tools",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.4",
|
|
5
5
|
"author": "Codenautas <codenautas@googlegroups.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"repository":
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/codenautas/sql-tools.git"
|
|
10
|
+
},
|
|
8
11
|
"contributors": [
|
|
9
12
|
{
|
|
10
13
|
"name": "Emilio Platzer",
|
|
@@ -12,13 +15,15 @@
|
|
|
12
15
|
}
|
|
13
16
|
],
|
|
14
17
|
"main": "bin/sql-tools.js",
|
|
15
|
-
"dependencies": {
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"type-store": "^0.4.5"
|
|
20
|
+
},
|
|
16
21
|
"devDependencies": {
|
|
17
22
|
"expect.js": "~0.3.1",
|
|
18
23
|
"istanbul": "~0.4.5",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"pg-promise-strict": "~1.
|
|
24
|
+
"mini-tools": "~1.13.4",
|
|
25
|
+
"mocha": "~11.7.5",
|
|
26
|
+
"pg-promise-strict": "~1.4.3"
|
|
22
27
|
},
|
|
23
28
|
"engines": {
|
|
24
29
|
"node": ">= 0.8.0"
|