@saltcorn/db-common 0.6.2-beta.4 → 0.6.3-beta.1
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/dist/coverage/lcov-report/block-navigation.d.ts +2 -0
- package/dist/coverage/lcov-report/block-navigation.d.ts.map +1 -0
- package/dist/coverage/lcov-report/block-navigation.js +66 -0
- package/dist/coverage/lcov-report/block-navigation.js.map +1 -0
- package/dist/coverage/lcov-report/prettify.d.ts +1 -0
- package/dist/coverage/lcov-report/prettify.d.ts.map +1 -0
- package/dist/coverage/lcov-report/prettify.js +478 -0
- package/dist/coverage/lcov-report/prettify.js.map +1 -0
- package/dist/coverage/lcov-report/sorter.d.ts +2 -0
- package/dist/coverage/lcov-report/sorter.d.ts.map +1 -0
- package/dist/coverage/lcov-report/sorter.js +141 -0
- package/dist/coverage/lcov-report/sorter.js.map +1 -0
- package/dist/internal.d.ts +91 -6
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +106 -139
- package/dist/internal.js.map +1 -1
- package/dist/internal.test.js +59 -1
- package/dist/internal.test.js.map +1 -1
- package/dist/multi-tenant.d.ts +1 -1
- package/dist/multi-tenant.d.ts.map +1 -1
- package/dist/multi-tenant.js.map +1 -1
- package/dist/single-tenant.d.ts +1 -1
- package/dist/single-tenant.d.ts.map +1 -1
- package/dist/single-tenant.js.map +1 -1
- package/dist/tsconfig.ref.tsbuildinfo +1 -1
- package/package.json +16 -9
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
var addSorting = (function () {
|
|
4
|
+
'use strict';
|
|
5
|
+
var cols, currentSort = {
|
|
6
|
+
index: 0,
|
|
7
|
+
desc: false
|
|
8
|
+
};
|
|
9
|
+
// returns the summary table element
|
|
10
|
+
function getTable() {
|
|
11
|
+
return document.querySelector('.coverage-summary');
|
|
12
|
+
}
|
|
13
|
+
// returns the thead element of the summary table
|
|
14
|
+
function getTableHeader() {
|
|
15
|
+
return getTable().querySelector('thead tr');
|
|
16
|
+
}
|
|
17
|
+
// returns the tbody element of the summary table
|
|
18
|
+
function getTableBody() {
|
|
19
|
+
return getTable().querySelector('tbody');
|
|
20
|
+
}
|
|
21
|
+
// returns the th element for nth column
|
|
22
|
+
function getNthColumn(n) {
|
|
23
|
+
return getTableHeader().querySelectorAll('th')[n];
|
|
24
|
+
}
|
|
25
|
+
// loads all columns
|
|
26
|
+
function loadColumns() {
|
|
27
|
+
var colNodes = getTableHeader().querySelectorAll('th'), colNode, cols = [], col, i;
|
|
28
|
+
for (i = 0; i < colNodes.length; i += 1) {
|
|
29
|
+
colNode = colNodes[i];
|
|
30
|
+
col = {
|
|
31
|
+
key: colNode.getAttribute('data-col'),
|
|
32
|
+
sortable: !colNode.getAttribute('data-nosort'),
|
|
33
|
+
type: colNode.getAttribute('data-type') || 'string'
|
|
34
|
+
};
|
|
35
|
+
cols.push(col);
|
|
36
|
+
if (col.sortable) {
|
|
37
|
+
col.defaultDescSort = col.type === 'number';
|
|
38
|
+
colNode.innerHTML =
|
|
39
|
+
colNode.innerHTML + '<span class="sorter"></span>';
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return cols;
|
|
43
|
+
}
|
|
44
|
+
// attaches a data attribute to every tr element with an object
|
|
45
|
+
// of data values keyed by column name
|
|
46
|
+
function loadRowData(tableRow) {
|
|
47
|
+
var tableCols = tableRow.querySelectorAll('td'), colNode, col, data = {}, i, val;
|
|
48
|
+
for (i = 0; i < tableCols.length; i += 1) {
|
|
49
|
+
colNode = tableCols[i];
|
|
50
|
+
col = cols[i];
|
|
51
|
+
val = colNode.getAttribute('data-value');
|
|
52
|
+
if (col.type === 'number') {
|
|
53
|
+
val = Number(val);
|
|
54
|
+
}
|
|
55
|
+
data[col.key] = val;
|
|
56
|
+
}
|
|
57
|
+
return data;
|
|
58
|
+
}
|
|
59
|
+
// loads all row data
|
|
60
|
+
function loadData() {
|
|
61
|
+
var rows = getTableBody().querySelectorAll('tr'), i;
|
|
62
|
+
for (i = 0; i < rows.length; i += 1) {
|
|
63
|
+
rows[i].data = loadRowData(rows[i]);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// sorts the table using the data for the ith column
|
|
67
|
+
function sortByIndex(index, desc) {
|
|
68
|
+
var key = cols[index].key, sorter = function (a, b) {
|
|
69
|
+
a = a.data[key];
|
|
70
|
+
b = b.data[key];
|
|
71
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
72
|
+
}, finalSorter = sorter, tableBody = document.querySelector('.coverage-summary tbody'), rowNodes = tableBody.querySelectorAll('tr'), rows = [], i;
|
|
73
|
+
if (desc) {
|
|
74
|
+
finalSorter = function (a, b) {
|
|
75
|
+
return -1 * sorter(a, b);
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
for (i = 0; i < rowNodes.length; i += 1) {
|
|
79
|
+
rows.push(rowNodes[i]);
|
|
80
|
+
tableBody.removeChild(rowNodes[i]);
|
|
81
|
+
}
|
|
82
|
+
rows.sort(finalSorter);
|
|
83
|
+
for (i = 0; i < rows.length; i += 1) {
|
|
84
|
+
tableBody.appendChild(rows[i]);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// removes sort indicators for current column being sorted
|
|
88
|
+
function removeSortIndicators() {
|
|
89
|
+
var col = getNthColumn(currentSort.index), cls = col.className;
|
|
90
|
+
cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, '');
|
|
91
|
+
col.className = cls;
|
|
92
|
+
}
|
|
93
|
+
// adds sort indicators for current column being sorted
|
|
94
|
+
function addSortIndicators() {
|
|
95
|
+
getNthColumn(currentSort.index).className += currentSort.desc
|
|
96
|
+
? ' sorted-desc'
|
|
97
|
+
: ' sorted';
|
|
98
|
+
}
|
|
99
|
+
// adds event listeners for all sorter widgets
|
|
100
|
+
function enableUI() {
|
|
101
|
+
var i, el, ithSorter = function ithSorter(i) {
|
|
102
|
+
var col = cols[i];
|
|
103
|
+
return function () {
|
|
104
|
+
var desc = col.defaultDescSort;
|
|
105
|
+
if (currentSort.index === i) {
|
|
106
|
+
desc = !currentSort.desc;
|
|
107
|
+
}
|
|
108
|
+
sortByIndex(i, desc);
|
|
109
|
+
removeSortIndicators();
|
|
110
|
+
currentSort.index = i;
|
|
111
|
+
currentSort.desc = desc;
|
|
112
|
+
addSortIndicators();
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
for (i = 0; i < cols.length; i += 1) {
|
|
116
|
+
if (cols[i].sortable) {
|
|
117
|
+
// add the click event handler on the th so users
|
|
118
|
+
// dont have to click on those tiny arrows
|
|
119
|
+
el = getNthColumn(i).querySelector('.sorter').parentElement;
|
|
120
|
+
if (el.addEventListener) {
|
|
121
|
+
el.addEventListener('click', ithSorter(i));
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
el.attachEvent('onclick', ithSorter(i));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// adds sorting functionality to the UI
|
|
130
|
+
return function () {
|
|
131
|
+
if (!getTable()) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
cols = loadColumns();
|
|
135
|
+
loadData();
|
|
136
|
+
addSortIndicators();
|
|
137
|
+
enableUI();
|
|
138
|
+
};
|
|
139
|
+
})();
|
|
140
|
+
window.addEventListener('load', addSorting);
|
|
141
|
+
//# sourceMappingURL=sorter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sorter.js","sourceRoot":"","sources":["../../../coverage/lcov-report/sorter.js"],"names":[],"mappings":";AAAA,oBAAoB;AACpB,IAAI,UAAU,GAAG,CAAC;IACd,YAAY,CAAC;IACb,IAAI,IAAI,EACJ,WAAW,GAAG;QACV,KAAK,EAAE,CAAC;QACR,IAAI,EAAE,KAAK;KACd,CAAC;IAEN,oCAAoC;IACpC,SAAS,QAAQ;QACb,OAAO,QAAQ,CAAC,aAAa,CAAC,mBAA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;iBAC3C;aACJ;SACJ;IACL,CAAC;IACD,uCAAuC;IACvC,OAAO;QACH,IAAI,CAAC,QAAQ,EAAE,EAAE;YACb,OAAO;SACV;QACD,IAAI,GAAG,WAAW,EAAE,CAAC;QACrB,QAAQ,EAAE,CAAC;QACX,iBAAiB,EAAE,CAAC;QACpB,QAAQ,EAAE,CAAC;IACf,CAAC,CAAC;AACN,CAAC,CAAC,EAAE,CAAC;AAEL,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC"}
|
package/dist/internal.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @category db-common
|
|
3
|
+
* @module internal
|
|
4
|
+
*/
|
|
1
5
|
/**
|
|
2
6
|
* Transform value to correct sql name.
|
|
3
7
|
* Note! Dont use other symbols than ^A-Za-z_0-9
|
|
@@ -5,7 +9,7 @@
|
|
|
5
9
|
* @param {string} nm
|
|
6
10
|
* @returns {string}
|
|
7
11
|
*/
|
|
8
|
-
export declare const sqlsanitize: (nm: string |
|
|
12
|
+
export declare const sqlsanitize: (nm: string | symbol) => string;
|
|
9
13
|
/**
|
|
10
14
|
* Transform value to correct sql name.
|
|
11
15
|
* Instead of sqlsanitize also allows .
|
|
@@ -15,10 +19,38 @@ export declare const sqlsanitize: (nm: string | any) => string;
|
|
|
15
19
|
* @param {string} nm
|
|
16
20
|
* @returns {string}
|
|
17
21
|
*/
|
|
18
|
-
export declare const sqlsanitizeAllowDots: (nm: string |
|
|
22
|
+
export declare const sqlsanitizeAllowDots: (nm: string | symbol) => string;
|
|
23
|
+
export declare type Value = string | number | boolean | Date | Value[];
|
|
24
|
+
export declare type Where = {
|
|
25
|
+
_fts?: {
|
|
26
|
+
fields: any[];
|
|
27
|
+
table?: string;
|
|
28
|
+
searchTerm: string;
|
|
29
|
+
};
|
|
30
|
+
or?: Where[];
|
|
31
|
+
not?: Where | symbol;
|
|
32
|
+
eq?: Value[];
|
|
33
|
+
[key: string]: {
|
|
34
|
+
in: Value[];
|
|
35
|
+
} | {
|
|
36
|
+
or: Value[];
|
|
37
|
+
} | {
|
|
38
|
+
gt: Value;
|
|
39
|
+
equal?: boolean;
|
|
40
|
+
} | {
|
|
41
|
+
lt: Value;
|
|
42
|
+
equal?: boolean;
|
|
43
|
+
} | Value[] | {
|
|
44
|
+
inSelect: {
|
|
45
|
+
where: Where;
|
|
46
|
+
field: string;
|
|
47
|
+
table: string;
|
|
48
|
+
};
|
|
49
|
+
} | null | symbol | any;
|
|
50
|
+
};
|
|
19
51
|
declare type WhereAndVals = {
|
|
20
52
|
where: string;
|
|
21
|
-
values:
|
|
53
|
+
values: Value[];
|
|
22
54
|
};
|
|
23
55
|
/**
|
|
24
56
|
* @param {object} whereObj
|
|
@@ -26,11 +58,64 @@ declare type WhereAndVals = {
|
|
|
26
58
|
* @param {number} initCount
|
|
27
59
|
* @returns {object}
|
|
28
60
|
*/
|
|
29
|
-
export declare const mkWhere: (whereObj:
|
|
61
|
+
export declare const mkWhere: (whereObj: Where, is_sqlite: boolean, initCount?: number) => WhereAndVals;
|
|
62
|
+
export declare type CoordOpts = {
|
|
63
|
+
latField: string;
|
|
64
|
+
longField: string;
|
|
65
|
+
lat: string;
|
|
66
|
+
long: string;
|
|
67
|
+
};
|
|
68
|
+
export declare type SelectOptions = {
|
|
69
|
+
orderBy?: {
|
|
70
|
+
distance: CoordOpts;
|
|
71
|
+
} | string;
|
|
72
|
+
limit?: string | number;
|
|
73
|
+
offset?: string | number;
|
|
74
|
+
nocase?: boolean;
|
|
75
|
+
orderDesc?: boolean;
|
|
76
|
+
cached?: boolean;
|
|
77
|
+
versioned?: boolean;
|
|
78
|
+
min_role_read?: number;
|
|
79
|
+
min_role_write?: number;
|
|
80
|
+
ownership_field_id?: string;
|
|
81
|
+
ownership_formula?: string;
|
|
82
|
+
description?: string;
|
|
83
|
+
};
|
|
84
|
+
export declare const orderByIsObject: (object: any) => object is {
|
|
85
|
+
distance: CoordOpts;
|
|
86
|
+
};
|
|
87
|
+
export declare type JoinField = {
|
|
88
|
+
ref: any;
|
|
89
|
+
target: any;
|
|
90
|
+
through: any;
|
|
91
|
+
[key: string]: any;
|
|
92
|
+
};
|
|
93
|
+
export declare type JoinOptions = {
|
|
94
|
+
joinFields?: JoinField;
|
|
95
|
+
aggregations?: AggregationOptions[];
|
|
96
|
+
where: any;
|
|
97
|
+
} & SelectOptions;
|
|
98
|
+
export declare type AggregationOptions = {
|
|
99
|
+
table: string;
|
|
100
|
+
ref: string;
|
|
101
|
+
field: string;
|
|
102
|
+
where?: string;
|
|
103
|
+
aggregate: string;
|
|
104
|
+
subselect?: SubselectOptions;
|
|
105
|
+
};
|
|
106
|
+
export declare type SubselectOptions = {
|
|
107
|
+
tableName: string;
|
|
108
|
+
whereField: string;
|
|
109
|
+
field: string;
|
|
110
|
+
table: any;
|
|
111
|
+
};
|
|
30
112
|
/**
|
|
31
113
|
* @param {object} selopts
|
|
32
|
-
* @returns {string
|
|
114
|
+
* @returns {string}
|
|
33
115
|
*/
|
|
34
|
-
export declare const mkSelectOptions: (selopts:
|
|
116
|
+
export declare const mkSelectOptions: (selopts: SelectOptions) => string;
|
|
117
|
+
export declare type Row = {
|
|
118
|
+
[key: string]: any;
|
|
119
|
+
};
|
|
35
120
|
export {};
|
|
36
121
|
//# sourceMappingURL=internal.d.ts.map
|
package/dist/internal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../internal.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../internal.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,OAAQ,MAAM,GAAG,MAAM,KAAG,MAOjD,CAAC;AACF;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,OAAQ,MAAM,GAAG,MAAM,KAAG,MAO1D,CAAC;AAsEF,oBA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MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,GAAG,CAAC;CACZ,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,eAAe,YAAa,aAAa,KAAG,MAoBxD,CAAC;AAEF,oBAAY,GAAG,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,CAAC"}
|
package/dist/internal.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mkSelectOptions = exports.mkWhere = exports.sqlsanitizeAllowDots = exports.sqlsanitize = void 0;
|
|
4
2
|
/**
|
|
5
3
|
* @category db-common
|
|
6
4
|
* @module internal
|
|
7
5
|
*/
|
|
8
|
-
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.mkSelectOptions = exports.orderByIsObject = exports.mkWhere = exports.sqlsanitizeAllowDots = exports.sqlsanitize = void 0;
|
|
9
8
|
//https://stackoverflow.com/questions/15300704/regex-with-my-jquery-function-for-sql-variable-name-validation
|
|
10
9
|
/**
|
|
11
10
|
* Transform value to correct sql name.
|
|
@@ -15,8 +14,9 @@ const { footer } = require("@saltcorn/markup/tags");
|
|
|
15
14
|
* @returns {string}
|
|
16
15
|
*/
|
|
17
16
|
const sqlsanitize = (nm) => {
|
|
18
|
-
if (typeof nm === "symbol")
|
|
19
|
-
return (0, exports.sqlsanitize)(nm.description);
|
|
17
|
+
if (typeof nm === "symbol") {
|
|
18
|
+
return nm.description ? (0, exports.sqlsanitize)(nm.description) : "";
|
|
19
|
+
}
|
|
20
20
|
const s = nm.replace(/[^A-Za-z_0-9]*/g, "");
|
|
21
21
|
if (s[0] >= "0" && s[0] <= "9")
|
|
22
22
|
return `_${s}`;
|
|
@@ -34,8 +34,9 @@ exports.sqlsanitize = sqlsanitize;
|
|
|
34
34
|
* @returns {string}
|
|
35
35
|
*/
|
|
36
36
|
const sqlsanitizeAllowDots = (nm) => {
|
|
37
|
-
if (typeof nm === "symbol")
|
|
38
|
-
return (0, exports.sqlsanitizeAllowDots)(nm.description);
|
|
37
|
+
if (typeof nm === "symbol") {
|
|
38
|
+
return nm.description ? (0, exports.sqlsanitizeAllowDots)(nm.description) : "";
|
|
39
|
+
}
|
|
39
40
|
const s = nm.replace(/[^A-Za-z_0-9."]*/g, "");
|
|
40
41
|
if (s[0] >= "0" && s[0] <= "9")
|
|
41
42
|
return `_${s}`;
|
|
@@ -43,6 +44,34 @@ const sqlsanitizeAllowDots = (nm) => {
|
|
|
43
44
|
return s;
|
|
44
45
|
};
|
|
45
46
|
exports.sqlsanitizeAllowDots = sqlsanitizeAllowDots;
|
|
47
|
+
const postgresPlaceHolderStack = (init = 0) => {
|
|
48
|
+
let values = [];
|
|
49
|
+
let i = init;
|
|
50
|
+
return {
|
|
51
|
+
push(x) {
|
|
52
|
+
values.push(x);
|
|
53
|
+
i += 1;
|
|
54
|
+
return `$${i}`;
|
|
55
|
+
},
|
|
56
|
+
is_sqlite: false,
|
|
57
|
+
getValues() {
|
|
58
|
+
return values;
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
const sqlitePlaceHolderStack = () => {
|
|
63
|
+
let values = [];
|
|
64
|
+
return {
|
|
65
|
+
push(x) {
|
|
66
|
+
values.push(x);
|
|
67
|
+
return `?`;
|
|
68
|
+
},
|
|
69
|
+
is_sqlite: true,
|
|
70
|
+
getValues() {
|
|
71
|
+
return values;
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
};
|
|
46
75
|
/**
|
|
47
76
|
*
|
|
48
77
|
* @param {object} v
|
|
@@ -50,9 +79,9 @@ exports.sqlsanitizeAllowDots = sqlsanitizeAllowDots;
|
|
|
50
79
|
* @param {boolean} is_sqlite
|
|
51
80
|
* @returns {string}
|
|
52
81
|
*/
|
|
53
|
-
const whereFTS = (v,
|
|
82
|
+
const whereFTS = (v, phs) => {
|
|
54
83
|
const { fields, table } = v;
|
|
55
|
-
|
|
84
|
+
let flds = fields
|
|
56
85
|
.filter((f) => f.type && f.type.sql_name === "text")
|
|
57
86
|
.map((f) => "coalesce(" +
|
|
58
87
|
(table
|
|
@@ -62,26 +91,10 @@ const whereFTS = (v, i, is_sqlite) => {
|
|
|
62
91
|
.join(" || ' ' || ");
|
|
63
92
|
if (flds === "")
|
|
64
93
|
flds = "''";
|
|
65
|
-
if (is_sqlite)
|
|
66
|
-
return `${flds} LIKE '%' ||
|
|
94
|
+
if (phs.is_sqlite)
|
|
95
|
+
return `${flds} LIKE '%' || ${phs.push(v.searchTerm)} || '%'`;
|
|
67
96
|
else
|
|
68
|
-
return `to_tsvector('english', ${flds}) @@ plainto_tsquery('english',
|
|
69
|
-
};
|
|
70
|
-
/**
|
|
71
|
-
* @param {boolean} is_sqlite
|
|
72
|
-
* @param {string} i
|
|
73
|
-
* @returns {string}
|
|
74
|
-
*/
|
|
75
|
-
const placeHolder = (is_sqlite, i) => is_sqlite ? `?` : `$${i}`;
|
|
76
|
-
/**
|
|
77
|
-
* @returns {number}
|
|
78
|
-
*/
|
|
79
|
-
const mkCounter = (init = 0) => {
|
|
80
|
-
let i = init;
|
|
81
|
-
return () => {
|
|
82
|
-
i += 1;
|
|
83
|
-
return i;
|
|
84
|
-
};
|
|
97
|
+
return `to_tsvector('english', ${flds}) @@ plainto_tsquery('english', ${phs.push(v.searchTerm)})`;
|
|
85
98
|
};
|
|
86
99
|
/**
|
|
87
100
|
*
|
|
@@ -89,27 +102,14 @@ const mkCounter = (init = 0) => {
|
|
|
89
102
|
* @param {string} i
|
|
90
103
|
* @returns {function}
|
|
91
104
|
*/
|
|
92
|
-
const subSelectWhere = (
|
|
105
|
+
const subSelectWhere = (phs) => (k, v) => {
|
|
93
106
|
const whereObj = v.inSelect.where;
|
|
94
107
|
const wheres = whereObj ? Object.entries(whereObj) : [];
|
|
95
108
|
const where = whereObj && wheres.length > 0
|
|
96
|
-
? "where " + wheres.map(whereClause(
|
|
109
|
+
? "where " + wheres.map(whereClause(phs)).join(" and ")
|
|
97
110
|
: "";
|
|
98
111
|
return `${quote((0, exports.sqlsanitizeAllowDots)(k))} in (select ${v.inSelect.field} from ${v.inSelect.table} ${where})`;
|
|
99
112
|
};
|
|
100
|
-
/**
|
|
101
|
-
* @param {object} v
|
|
102
|
-
* @returns {object[]}
|
|
103
|
-
*/
|
|
104
|
-
const subSelectVals = (v) => {
|
|
105
|
-
const whereObj = v.inSelect.where;
|
|
106
|
-
const wheres = whereObj ? Object.entries(whereObj) : [];
|
|
107
|
-
const xs = wheres
|
|
108
|
-
.map(getVal)
|
|
109
|
-
.flat(1)
|
|
110
|
-
.filter((v) => v !== null);
|
|
111
|
-
return xs;
|
|
112
|
-
};
|
|
113
113
|
/**
|
|
114
114
|
* @param {string} s
|
|
115
115
|
* @returns {string}
|
|
@@ -119,21 +119,25 @@ const wrapParens = (s) => (s ? `(${s})` : s);
|
|
|
119
119
|
* @param {string} s
|
|
120
120
|
* @returns {string}
|
|
121
121
|
*/
|
|
122
|
-
const quote = (s) => s.includes(".")
|
|
122
|
+
const quote = (s) => s.includes(".")
|
|
123
|
+
? s.split(".").map(quote).join(".")
|
|
124
|
+
: s.includes('"')
|
|
125
|
+
? s
|
|
126
|
+
: `"${s}"`;
|
|
123
127
|
/**
|
|
124
128
|
* @param {boolean} is_sqlite
|
|
125
129
|
* @param {string} i
|
|
126
130
|
* @returns {function}
|
|
127
131
|
*/
|
|
128
|
-
const whereOr = (
|
|
132
|
+
const whereOr = (phs) => (ors) => wrapParens(ors
|
|
129
133
|
.map((vi) => Object.entries(vi)
|
|
130
|
-
.map((kv) => whereClause(
|
|
134
|
+
.map((kv) => whereClause(phs)(kv))
|
|
131
135
|
.join(" and "))
|
|
132
136
|
.join(" or "));
|
|
133
|
-
const equals = ([v1, v2],
|
|
137
|
+
const equals = ([v1, v2], phs) => {
|
|
134
138
|
const pVal = (v) => typeof v === "symbol"
|
|
135
|
-
? quote((0, exports.sqlsanitizeAllowDots)(v
|
|
136
|
-
:
|
|
139
|
+
? quote((0, exports.sqlsanitizeAllowDots)(v))
|
|
140
|
+
: phs.push(v) + (typeof v === "string" ? "::text" : "");
|
|
137
141
|
const isNull = (v) => `${pVal(v)} is null`;
|
|
138
142
|
if (v1 === null && v2 === null)
|
|
139
143
|
return "null is null";
|
|
@@ -143,92 +147,50 @@ const equals = ([v1, v2], is_sqlite, i) => {
|
|
|
143
147
|
return isNull(v1);
|
|
144
148
|
return `${pVal(v1)}=${pVal(v2)}`;
|
|
145
149
|
};
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
if (v !== null && typeof v !== "symbol")
|
|
150
|
-
vals.push(v);
|
|
151
|
-
});
|
|
152
|
-
//console.log({ vals });
|
|
153
|
-
return vals;
|
|
154
|
-
};
|
|
150
|
+
const slugifyQuery = (k, s, phs) => phs.is_sqlite
|
|
151
|
+
? `REPLACE(LOWER(${quote((0, exports.sqlsanitizeAllowDots)(k))}),' ','-')=${phs.push(s)}`
|
|
152
|
+
: `REGEXP_REPLACE(REPLACE(LOWER(${quote((0, exports.sqlsanitizeAllowDots)(k))}),' ','-'),'[^\\w-]','','g')=${phs.push(s)}`;
|
|
155
153
|
/**
|
|
156
154
|
* @param {boolean} is_sqlite
|
|
157
155
|
* @param {string} i
|
|
158
156
|
* @returns {function}
|
|
159
157
|
*/
|
|
160
|
-
const whereClause = (
|
|
161
|
-
? whereFTS(v,
|
|
158
|
+
const whereClause = (phs) => ([k, v]) => k === "_fts"
|
|
159
|
+
? whereFTS(v, phs)
|
|
162
160
|
: typeof (v || {}).in !== "undefined"
|
|
163
|
-
? `${quote((0, exports.sqlsanitizeAllowDots)(k))} = ${is_sqlite ? "" : "ANY"} (${
|
|
161
|
+
? `${quote((0, exports.sqlsanitizeAllowDots)(k))} = ${phs.is_sqlite ? "" : "ANY"} (${phs.push(v.in)})`
|
|
164
162
|
: k === "or" && Array.isArray(v)
|
|
165
|
-
? whereOr(
|
|
166
|
-
:
|
|
167
|
-
?
|
|
168
|
-
|
|
169
|
-
.
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
: Array.isArray(v)
|
|
176
|
-
? v.map((vi) => whereClause(
|
|
177
|
-
:
|
|
178
|
-
?
|
|
179
|
-
: typeof (v || {}).
|
|
180
|
-
? `${quote((0, exports.sqlsanitizeAllowDots)(k))}
|
|
181
|
-
: typeof (v || {}).
|
|
182
|
-
? `${quote((0, exports.sqlsanitizeAllowDots)(k))}
|
|
183
|
-
: typeof (v || {}).
|
|
184
|
-
?
|
|
185
|
-
: typeof (v || {}).
|
|
186
|
-
?
|
|
187
|
-
? `json_extract(${quote((0, exports.sqlsanitizeAllowDots)(k))}, '$.${(0, exports.sqlsanitizeAllowDots)(v.json[0])}')=${placeHolder(is_sqlite, i())}`
|
|
188
|
-
: `${quote((0, exports.sqlsanitizeAllowDots)(k))}->>'${(0, exports.sqlsanitizeAllowDots)(v.json[0])}'=${placeHolder(is_sqlite, i())}`
|
|
189
|
-
: v === null
|
|
190
|
-
? `${quote((0, exports.sqlsanitizeAllowDots)(k))} is null`
|
|
191
|
-
: k === "not"
|
|
192
|
-
? `not (${typeof v === "symbol" ? v.description : placeHolder(is_sqlite, i())})`
|
|
193
|
-
: `${quote((0, exports.sqlsanitizeAllowDots)(k))}=${typeof v === "symbol" ? v.description : placeHolder(is_sqlite, i())}`;
|
|
194
|
-
/**
|
|
195
|
-
* @param {object[]} opts
|
|
196
|
-
* @param {object} opts.k
|
|
197
|
-
* @param {object} opts.v
|
|
198
|
-
* @returns {boolean|object}
|
|
199
|
-
*/
|
|
200
|
-
const getVal = ([k, v]) => k === "_fts"
|
|
201
|
-
? v.searchTerm
|
|
202
|
-
: typeof (v || {}).in !== "undefined"
|
|
203
|
-
? [v.in]
|
|
204
|
-
: k === "not" && typeof v === "object"
|
|
205
|
-
? Object.entries(v).map(getVal).flat(1)
|
|
206
|
-
: k === "eq" && Array.isArray(v)
|
|
207
|
-
? equalsVals(v).flat(1)
|
|
208
|
-
: k === "or" && Array.isArray(v)
|
|
209
|
-
? v
|
|
210
|
-
.map((vi) => Object.entries(vi).map(getVal))
|
|
211
|
-
.flat(1)
|
|
212
|
-
.flat(1)
|
|
213
|
-
: v && v.or && Array.isArray(v.or)
|
|
214
|
-
? v.or.map((vi) => getVal([k, vi])).flat(1)
|
|
215
|
-
: Array.isArray(v)
|
|
216
|
-
? v.map((vi) => getVal([k, vi])).flat(1)
|
|
217
|
-
: typeof (v || {}).ilike !== "undefined"
|
|
218
|
-
? v.ilike
|
|
219
|
-
: typeof (v || {}).inSelect !== "undefined"
|
|
220
|
-
? subSelectVals(v)
|
|
221
|
-
: typeof (v || {}).lt !== "undefined"
|
|
222
|
-
? v.lt
|
|
223
|
-
: typeof (v || {}).gt !== "undefined"
|
|
224
|
-
? v.gt
|
|
225
|
-
: typeof (v || {}).sql !== "undefined"
|
|
226
|
-
? null
|
|
163
|
+
? whereOr(phs)(v)
|
|
164
|
+
: typeof (v || {}).slugify !== "undefined"
|
|
165
|
+
? slugifyQuery(k, v.slugify, phs)
|
|
166
|
+
: k === "not" && typeof v === "object"
|
|
167
|
+
? `not (${Object.entries(v)
|
|
168
|
+
.map((kv) => whereClause(phs)(kv))
|
|
169
|
+
.join(" and ")})`
|
|
170
|
+
: k === "eq" && Array.isArray(v)
|
|
171
|
+
? // @ts-ignore
|
|
172
|
+
equals(v, phs)
|
|
173
|
+
: v && v.or && Array.isArray(v.or)
|
|
174
|
+
? wrapParens(v.or.map((vi) => whereClause(phs)([k, vi])).join(" or "))
|
|
175
|
+
: Array.isArray(v)
|
|
176
|
+
? v.map((vi) => whereClause(phs)([k, vi])).join(" and ")
|
|
177
|
+
: typeof (v || {}).ilike !== "undefined"
|
|
178
|
+
? `${quote((0, exports.sqlsanitizeAllowDots)(k))} ${phs.is_sqlite ? "LIKE" : "ILIKE"} '%' || ${phs.push(v.ilike)} || '%'`
|
|
179
|
+
: typeof (v || {}).gt !== "undefined"
|
|
180
|
+
? `${quote((0, exports.sqlsanitizeAllowDots)(k))}>${v.equal ? "=" : ""}${phs.push(v.gt)}`
|
|
181
|
+
: typeof (v || {}).lt !== "undefined"
|
|
182
|
+
? `${quote((0, exports.sqlsanitizeAllowDots)(k))}<${v.equal ? "=" : ""}${phs.push(v.lt)}`
|
|
183
|
+
: typeof (v || {}).inSelect !== "undefined"
|
|
184
|
+
? subSelectWhere(phs)(k, v)
|
|
227
185
|
: typeof (v || {}).json !== "undefined"
|
|
228
|
-
?
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
186
|
+
? phs.is_sqlite
|
|
187
|
+
? `json_extract(${quote((0, exports.sqlsanitizeAllowDots)(k))}, '$.${(0, exports.sqlsanitizeAllowDots)(v.json[0])}')=${phs.push(v.json[1])}`
|
|
188
|
+
: `${quote((0, exports.sqlsanitizeAllowDots)(k))}->>'${(0, exports.sqlsanitizeAllowDots)(v.json[0])}'=${phs.push(v.json[1])}`
|
|
189
|
+
: v === null
|
|
190
|
+
? `${quote((0, exports.sqlsanitizeAllowDots)(k))} is null`
|
|
191
|
+
: k === "not"
|
|
192
|
+
? `not (${typeof v === "symbol" ? v.description : phs.push(v)})`
|
|
193
|
+
: `${quote((0, exports.sqlsanitizeAllowDots)(k))}=${typeof v === "symbol" ? v.description : phs.push(v)}`;
|
|
232
194
|
/**
|
|
233
195
|
* @param {object} whereObj
|
|
234
196
|
* @param {boolean} is_sqlite
|
|
@@ -238,14 +200,13 @@ const getVal = ([k, v]) => k === "_fts"
|
|
|
238
200
|
const mkWhere = (whereObj, is_sqlite, initCount = 0) => {
|
|
239
201
|
const wheres = whereObj ? Object.entries(whereObj) : [];
|
|
240
202
|
//console.log({ wheres });
|
|
203
|
+
const placeHolderStack = is_sqlite
|
|
204
|
+
? sqlitePlaceHolderStack()
|
|
205
|
+
: postgresPlaceHolderStack(initCount);
|
|
241
206
|
const where = whereObj && wheres.length > 0
|
|
242
|
-
? "where " +
|
|
243
|
-
wheres.map(whereClause(is_sqlite, mkCounter(initCount))).join(" and ")
|
|
207
|
+
? "where " + wheres.map(whereClause(placeHolderStack)).join(" and ")
|
|
244
208
|
: "";
|
|
245
|
-
const values =
|
|
246
|
-
.map(getVal)
|
|
247
|
-
.flat(1)
|
|
248
|
-
.filter((v) => v !== null);
|
|
209
|
+
const values = placeHolderStack.getValues();
|
|
249
210
|
return { where, values };
|
|
250
211
|
};
|
|
251
212
|
exports.mkWhere = mkWhere;
|
|
@@ -270,19 +231,25 @@ const getDistanceOrder = ({ latField, longField, lat, long }) => {
|
|
|
270
231
|
const cos_lat_2 = Math.pow(Math.cos((+lat * Math.PI) / 180), 2);
|
|
271
232
|
return `((${(0, exports.sqlsanitizeAllowDots)(latField)} - ${+lat})*(${(0, exports.sqlsanitizeAllowDots)(latField)} - ${+lat})) + ((${(0, exports.sqlsanitizeAllowDots)(longField)} - ${+long})*(${(0, exports.sqlsanitizeAllowDots)(longField)} - ${+long})*${cos_lat_2})`;
|
|
272
233
|
};
|
|
234
|
+
const orderByIsObject = (object) => {
|
|
235
|
+
return object && object.distance;
|
|
236
|
+
};
|
|
237
|
+
exports.orderByIsObject = orderByIsObject;
|
|
273
238
|
/**
|
|
274
239
|
* @param {object} selopts
|
|
275
|
-
* @returns {string
|
|
240
|
+
* @returns {string}
|
|
276
241
|
*/
|
|
277
242
|
const mkSelectOptions = (selopts) => {
|
|
278
243
|
const orderby = selopts.orderBy === "RANDOM()"
|
|
279
244
|
? "order by RANDOM()"
|
|
280
|
-
: selopts.orderBy &&
|
|
245
|
+
: selopts.orderBy &&
|
|
246
|
+
typeof selopts.orderBy === "object" &&
|
|
247
|
+
selopts.orderBy.distance
|
|
281
248
|
? `order by ${getDistanceOrder(selopts.orderBy.distance)}`
|
|
282
|
-
: selopts.orderBy && selopts.nocase
|
|
283
|
-
? `order by lower(${(0, exports.sqlsanitizeAllowDots)(selopts.orderBy)})${selopts.orderDesc ? " DESC" : ""}`
|
|
284
|
-
: selopts.orderBy
|
|
285
|
-
? `order by ${(0, exports.sqlsanitizeAllowDots)(selopts.orderBy)}${selopts.orderDesc ? " DESC" : ""}`
|
|
249
|
+
: selopts.orderBy && typeof selopts.orderBy === "string" && selopts.nocase
|
|
250
|
+
? `order by lower(${quote((0, exports.sqlsanitizeAllowDots)(selopts.orderBy))})${selopts.orderDesc ? " DESC" : ""}`
|
|
251
|
+
: selopts.orderBy && typeof selopts.orderBy === "string"
|
|
252
|
+
? `order by ${quote((0, exports.sqlsanitizeAllowDots)(selopts.orderBy))}${selopts.orderDesc ? " DESC" : ""}`
|
|
286
253
|
: "";
|
|
287
254
|
const limit = selopts.limit ? `limit ${toInt(selopts.limit)}` : "";
|
|
288
255
|
const offset = selopts.offset ? `offset ${toInt(selopts.offset)}` : "";
|