taon-type-sql 21.0.22 → 21.0.23
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/browser/package.json +1 -1
- package/browser-prod/package.json +1 -1
- package/lib/build-info._auto-generated_.d.ts +1 -1
- package/lib/build-info._auto-generated_.js +1 -1
- package/lib/package.json +1 -1
- package/lib-prod/build-info._auto-generated_.js +14 -0
- package/lib-prod/builder/column/basic-column.js +13 -0
- package/lib-prod/builder/column/boolean-column.js +14 -0
- package/lib-prod/builder/column/comparable-column.js +42 -0
- package/lib-prod/builder/column/date-column.js +14 -0
- package/lib-prod/builder/column/number-column.js +19 -0
- package/lib-prod/builder/column/query-column.js +24 -0
- package/lib-prod/builder/column/string-column.js +36 -0
- package/lib-prod/builder/column/value-column.js +29 -0
- package/lib-prod/builder/condition/query-column-condition.js +22 -0
- package/lib-prod/builder/condition/query-condition-chain.js +33 -0
- package/lib-prod/builder/condition/query-condition.js +6 -0
- package/lib-prod/builder/condition/query-join-condition.js +22 -0
- package/lib-prod/builder/helpers/generics-helper.js +5 -0
- package/lib-prod/builder/helpers/internal-types.js +0 -0
- package/lib-prod/builder/join/joined-tables-chain.js +14 -0
- package/lib-prod/builder/join/joined-tables.js +22 -0
- package/lib-prod/builder/other/query-ordering.js +20 -0
- package/lib-prod/builder/query/select-query.js +51 -0
- package/lib-prod/builder/query/table-condition-query.js +27 -0
- package/lib-prod/builder/query/table-query.js +54 -0
- package/lib-prod/builder/query-source.js +18 -0
- package/lib-prod/builder/query-table.js +27 -0
- package/lib-prod/client/mysql.js +10 -0
- package/lib-prod/client/pg.js +10 -0
- package/lib-prod/client/query-processor.js +44 -0
- package/lib-prod/converter/param-converter.js +23 -0
- package/lib-prod/converter/parameterized-converter.js +17 -0
- package/lib-prod/converter/query-converter.js +268 -0
- package/lib-prod/converter/result-converter.js +77 -0
- package/lib-prod/converter/sql-converter.js +8 -0
- package/lib-prod/converter/type-converter.js +32 -0
- package/lib-prod/converter/types.js +0 -0
- package/lib-prod/env/env.angular-node-app.js +130 -0
- package/lib-prod/env/env.docs-webapp.js +130 -0
- package/lib-prod/env/env.electron-app.js +130 -0
- package/lib-prod/env/env.mobile-app.js +130 -0
- package/lib-prod/env/env.npm-lib-and-cli-tool.js +130 -0
- package/lib-prod/env/env.vscode-plugin.js +130 -0
- package/lib-prod/env/index.js +6 -0
- package/lib-prod/index._auto-generated_.js +0 -0
- package/lib-prod/index.js +46 -0
- package/lib-prod/migrations/index.js +1 -0
- package/lib-prod/migrations/migrations_index._auto-generated_.js +0 -0
- package/lib-prod/package.json +1 -1
- package/package.json +1 -1
- package/websql/package.json +1 -1
- package/websql-prod/package.json +1 -1
- package/lib-prod/build-info._auto-generated_.ts +0 -27
- package/lib-prod/builder/column/basic-column.ts +0 -17
- package/lib-prod/builder/column/boolean-column.ts +0 -19
- package/lib-prod/builder/column/comparable-column.ts +0 -56
- package/lib-prod/builder/column/date-column.ts +0 -19
- package/lib-prod/builder/column/number-column.ts +0 -25
- package/lib-prod/builder/column/query-column.ts +0 -34
- package/lib-prod/builder/column/string-column.ts +0 -47
- package/lib-prod/builder/column/value-column.ts +0 -39
- package/lib-prod/builder/condition/query-column-condition.ts +0 -28
- package/lib-prod/builder/condition/query-condition-chain.ts +0 -42
- package/lib-prod/builder/condition/query-condition.ts +0 -13
- package/lib-prod/builder/condition/query-join-condition.ts +0 -27
- package/lib-prod/builder/helpers/generics-helper.ts +0 -2
- package/lib-prod/builder/helpers/internal-types.ts +0 -31
- package/lib-prod/builder/join/joined-tables-chain.ts +0 -17
- package/lib-prod/builder/join/joined-tables.ts +0 -28
- package/lib-prod/builder/other/query-ordering.ts +0 -26
- package/lib-prod/builder/query/select-query.ts +0 -68
- package/lib-prod/builder/query/table-condition-query.ts +0 -35
- package/lib-prod/builder/query/table-query.ts +0 -72
- package/lib-prod/builder/query-source.ts +0 -25
- package/lib-prod/builder/query-table.ts +0 -34
- package/lib-prod/client/mysql.ts +0 -9
- package/lib-prod/client/pg.ts +0 -9
- package/lib-prod/client/query-processor.ts +0 -89
- package/lib-prod/converter/param-converter.ts +0 -23
- package/lib-prod/converter/parameterized-converter.ts +0 -20
- package/lib-prod/converter/query-converter.ts +0 -296
- package/lib-prod/converter/result-converter.ts +0 -88
- package/lib-prod/converter/sql-converter.ts +0 -7
- package/lib-prod/converter/type-converter.ts +0 -29
- package/lib-prod/converter/types.ts +0 -6
- package/lib-prod/env/env.angular-node-app.ts +0 -66
- package/lib-prod/env/env.docs-webapp.ts +0 -66
- package/lib-prod/env/env.electron-app.ts +0 -66
- package/lib-prod/env/env.mobile-app.ts +0 -66
- package/lib-prod/env/env.npm-lib-and-cli-tool.ts +0 -66
- package/lib-prod/env/env.vscode-plugin.ts +0 -66
- package/lib-prod/env/index.ts +0 -6
- package/lib-prod/index._auto-generated_.ts +0 -5
- package/lib-prod/index.ts +0 -37
- package/lib-prod/lib-info.md +0 -8
- package/lib-prod/migrations/index.ts +0 -2
- package/lib-prod/migrations/migrations-info.md +0 -6
- package/lib-prod/migrations/migrations_index._auto-generated_.ts +0 -5
package/browser/package.json
CHANGED
|
@@ -25,6 +25,6 @@ exports.CURRENT_PACKAGE_TAON_VERSION = 'v21';
|
|
|
25
25
|
/**
|
|
26
26
|
* Autogenerated by current cli tool. Use *tnp release* to bump version.
|
|
27
27
|
*/
|
|
28
|
-
exports.CURRENT_PACKAGE_VERSION = '21.0.
|
|
28
|
+
exports.CURRENT_PACKAGE_VERSION = '21.0.23';
|
|
29
29
|
// THIS FILE IS GENERATED - DO NOT MODIFY
|
|
30
30
|
//# sourceMappingURL=build-info._auto-generated_.js.map
|
package/lib/package.json
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const BUILD_FRAMEWORK_CLI_NAME = "tnp";
|
|
2
|
+
const APP_ID = "com.domain.example.taon-type-sql";
|
|
3
|
+
const BUILD_BASE_HREF = "";
|
|
4
|
+
const PROJECT_NPM_NAME = "taon-type-sql";
|
|
5
|
+
const CURRENT_PACKAGE_TAON_VERSION = "v21";
|
|
6
|
+
const CURRENT_PACKAGE_VERSION = "21.0.23";
|
|
7
|
+
export {
|
|
8
|
+
APP_ID,
|
|
9
|
+
BUILD_BASE_HREF,
|
|
10
|
+
BUILD_FRAMEWORK_CLI_NAME,
|
|
11
|
+
CURRENT_PACKAGE_TAON_VERSION,
|
|
12
|
+
CURRENT_PACKAGE_VERSION,
|
|
13
|
+
PROJECT_NPM_NAME
|
|
14
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import QueryColumn from "./query-column";
|
|
2
|
+
import NumberColumn from "./number-column";
|
|
3
|
+
class BasicColumn extends QueryColumn {
|
|
4
|
+
constructor(table, name, modifiers = []) {
|
|
5
|
+
super(table, name, modifiers);
|
|
6
|
+
}
|
|
7
|
+
count() {
|
|
8
|
+
return new NumberColumn(this._table, this._name, this._modifiers.concat({ name: "count" }));
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
BasicColumn as default
|
|
13
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import NumberColumn from "./number-column";
|
|
2
|
+
import ValueColumn from "./value-column";
|
|
3
|
+
class BooleanColumn extends ValueColumn {
|
|
4
|
+
_type = "boolean";
|
|
5
|
+
constructor(table, name, modifiers = []) {
|
|
6
|
+
super(table, name, modifiers);
|
|
7
|
+
}
|
|
8
|
+
count() {
|
|
9
|
+
return new NumberColumn(this._table, this._name, this._modifiers.concat({ name: "count" }));
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
BooleanColumn as default
|
|
14
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import QueryColumnCondition from "../condition/query-column-condition";
|
|
2
|
+
import ValueColumn from "./value-column";
|
|
3
|
+
class ComparableColumn extends ValueColumn {
|
|
4
|
+
constructor(table, name, modifiers = []) {
|
|
5
|
+
super(table, name, modifiers);
|
|
6
|
+
}
|
|
7
|
+
lt(value) {
|
|
8
|
+
return new QueryColumnCondition(this, "lt", value);
|
|
9
|
+
}
|
|
10
|
+
gt(value) {
|
|
11
|
+
return new QueryColumnCondition(this, "gt", value);
|
|
12
|
+
}
|
|
13
|
+
lte(value) {
|
|
14
|
+
return new QueryColumnCondition(this, "lte", value);
|
|
15
|
+
}
|
|
16
|
+
gte(value) {
|
|
17
|
+
return new QueryColumnCondition(this, "gte", value);
|
|
18
|
+
}
|
|
19
|
+
in(values) {
|
|
20
|
+
return new QueryColumnCondition(this, "in", ...values);
|
|
21
|
+
}
|
|
22
|
+
notIn(values) {
|
|
23
|
+
return new QueryColumnCondition(this, "not-in", ...values);
|
|
24
|
+
}
|
|
25
|
+
between(value1, value2) {
|
|
26
|
+
return new QueryColumnCondition(this, "between", value1, value2);
|
|
27
|
+
}
|
|
28
|
+
notBetween(value1, value2) {
|
|
29
|
+
return new QueryColumnCondition(this, "not-between", value1, value2);
|
|
30
|
+
}
|
|
31
|
+
// min/max exists for text columns too, not just numeric and date
|
|
32
|
+
min() {
|
|
33
|
+
return new this.constructor(this._table, this._name, this._modifiers.concat({ name: "min" }));
|
|
34
|
+
}
|
|
35
|
+
max() {
|
|
36
|
+
return new this.constructor(this._table, this._name, this._modifiers.concat({ name: "max" }));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
var comparable_column_default = ComparableColumn;
|
|
40
|
+
export {
|
|
41
|
+
comparable_column_default as default
|
|
42
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import ComparableColumn from "./comparable-column";
|
|
2
|
+
import NumberColumn from "./number-column";
|
|
3
|
+
class DateColumn extends ComparableColumn {
|
|
4
|
+
_type = "date";
|
|
5
|
+
constructor(table, name, modifiers = []) {
|
|
6
|
+
super(table, name, modifiers);
|
|
7
|
+
}
|
|
8
|
+
count() {
|
|
9
|
+
return new NumberColumn(this._table, this._name, this._modifiers.concat({ name: "count" }));
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
DateColumn as default
|
|
14
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import ComparableColumn from "./comparable-column";
|
|
2
|
+
class NumberColumn extends ComparableColumn {
|
|
3
|
+
_type = "number";
|
|
4
|
+
constructor(table, name, modifiers = []) {
|
|
5
|
+
super(table, name, modifiers);
|
|
6
|
+
}
|
|
7
|
+
count() {
|
|
8
|
+
return new NumberColumn(this._table, this._name, this._modifiers.concat({ name: "count" }));
|
|
9
|
+
}
|
|
10
|
+
sum() {
|
|
11
|
+
return new NumberColumn(this._table, this._name, this._modifiers.concat({ name: "sum" }));
|
|
12
|
+
}
|
|
13
|
+
avg() {
|
|
14
|
+
return new NumberColumn(this._table, this._name, this._modifiers.concat({ name: "avg" }));
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
NumberColumn as default
|
|
19
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import QueryColumnCondition from "../condition/query-column-condition";
|
|
2
|
+
class QueryColumn {
|
|
3
|
+
constructor(_table, _name, _modifiers = []) {
|
|
4
|
+
this._table = _table;
|
|
5
|
+
this._name = _name;
|
|
6
|
+
this._modifiers = _modifiers;
|
|
7
|
+
}
|
|
8
|
+
_$type;
|
|
9
|
+
_type;
|
|
10
|
+
// TODO I had to copy-paste the implementation to every child class to avoid a circular dependency
|
|
11
|
+
as(alias) {
|
|
12
|
+
return new this.constructor(this._table, this._name, this._modifiers.concat({ name: "as", params: alias }));
|
|
13
|
+
}
|
|
14
|
+
isNull() {
|
|
15
|
+
return new QueryColumnCondition(this, "is-null");
|
|
16
|
+
}
|
|
17
|
+
isNotNull() {
|
|
18
|
+
return new QueryColumnCondition(this, "is-not-null");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
var query_column_default = QueryColumn;
|
|
22
|
+
export {
|
|
23
|
+
query_column_default as default
|
|
24
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import ComparableColumn from "./comparable-column";
|
|
2
|
+
import NumberColumn from "./number-column";
|
|
3
|
+
import QueryColumnCondition from "../condition/query-column-condition";
|
|
4
|
+
class StringColumn extends ComparableColumn {
|
|
5
|
+
_type = "string";
|
|
6
|
+
constructor(table, name, modifiers = []) {
|
|
7
|
+
super(table, name, modifiers);
|
|
8
|
+
}
|
|
9
|
+
count() {
|
|
10
|
+
return new NumberColumn(this._table, this._name, this._modifiers.concat({ name: "count" }));
|
|
11
|
+
}
|
|
12
|
+
lower() {
|
|
13
|
+
return new this.constructor(this._table, this._name, this._modifiers.concat({ name: "lower" }));
|
|
14
|
+
}
|
|
15
|
+
upper() {
|
|
16
|
+
return new this.constructor(this._table, this._name, this._modifiers.concat({ name: "upper" }));
|
|
17
|
+
}
|
|
18
|
+
contains(value) {
|
|
19
|
+
return this.like("%" + value + "%");
|
|
20
|
+
}
|
|
21
|
+
startsWith(value) {
|
|
22
|
+
return this.like(value + "%");
|
|
23
|
+
}
|
|
24
|
+
endsWith(value) {
|
|
25
|
+
return this.like("%" + value);
|
|
26
|
+
}
|
|
27
|
+
like(value) {
|
|
28
|
+
return new QueryColumnCondition(this, "like", value);
|
|
29
|
+
}
|
|
30
|
+
notLike(value) {
|
|
31
|
+
return new QueryColumnCondition(this, "not-like", value);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
StringColumn as default
|
|
36
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import QueryColumnCondition from "../condition/query-column-condition";
|
|
2
|
+
import QueryOrdering from "../other/query-ordering";
|
|
3
|
+
import QueryColumn from "./query-column";
|
|
4
|
+
import QueryJoinCondition from "../condition/query-join-condition";
|
|
5
|
+
class ValueColumn extends QueryColumn {
|
|
6
|
+
constructor(table, name, modifiers = []) {
|
|
7
|
+
super(table, name, modifiers);
|
|
8
|
+
}
|
|
9
|
+
asc() {
|
|
10
|
+
return new QueryOrdering(this, "ASC");
|
|
11
|
+
}
|
|
12
|
+
desc() {
|
|
13
|
+
return new QueryOrdering(this, "DESC");
|
|
14
|
+
}
|
|
15
|
+
eq(value) {
|
|
16
|
+
if (value instanceof QueryColumn) {
|
|
17
|
+
return new QueryJoinCondition(this, "eq", value);
|
|
18
|
+
} else {
|
|
19
|
+
return new QueryColumnCondition(this, "eq", value);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
ne(value) {
|
|
23
|
+
return new QueryColumnCondition(this, "ne", value);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
var value_column_default = ValueColumn;
|
|
27
|
+
export {
|
|
28
|
+
value_column_default as default
|
|
29
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import QueryCondition from "./query-condition";
|
|
2
|
+
import QueryConditionChain from "./query-condition-chain";
|
|
3
|
+
class QueryColumnCondition extends QueryCondition {
|
|
4
|
+
_column;
|
|
5
|
+
_type;
|
|
6
|
+
_values;
|
|
7
|
+
constructor(column, type, ...values) {
|
|
8
|
+
super();
|
|
9
|
+
this._column = column;
|
|
10
|
+
this._type = type;
|
|
11
|
+
this._values = values;
|
|
12
|
+
}
|
|
13
|
+
and(condition) {
|
|
14
|
+
return new QueryConditionChain(this, condition, "and");
|
|
15
|
+
}
|
|
16
|
+
or(condition) {
|
|
17
|
+
return new QueryConditionChain(this, condition, "or");
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
QueryColumnCondition as default
|
|
22
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import QueryCondition from "./query-condition";
|
|
2
|
+
class QueryConditionChain extends QueryCondition {
|
|
3
|
+
_$type;
|
|
4
|
+
_sibling;
|
|
5
|
+
_child;
|
|
6
|
+
_chainType;
|
|
7
|
+
_parenthesis = false;
|
|
8
|
+
_negation = false;
|
|
9
|
+
constructor(sibling, child, chainType) {
|
|
10
|
+
super();
|
|
11
|
+
this._sibling = sibling;
|
|
12
|
+
this._child = child;
|
|
13
|
+
this._chainType = chainType;
|
|
14
|
+
}
|
|
15
|
+
// TODO how to call this
|
|
16
|
+
$() {
|
|
17
|
+
this._parenthesis = true;
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
not() {
|
|
21
|
+
this._negation = true;
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
and(condition) {
|
|
25
|
+
return new QueryConditionChain(this, condition, "and");
|
|
26
|
+
}
|
|
27
|
+
or(condition) {
|
|
28
|
+
return new QueryConditionChain(this, condition, "or");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
QueryConditionChain as default
|
|
33
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import QueryCondition from "./query-condition";
|
|
2
|
+
import QueryConditionChain from "./query-condition-chain";
|
|
3
|
+
class QueryJoinCondition extends QueryCondition {
|
|
4
|
+
_column;
|
|
5
|
+
_type;
|
|
6
|
+
_otherColumn;
|
|
7
|
+
constructor(column, type, otherColumn) {
|
|
8
|
+
super();
|
|
9
|
+
this._column = column;
|
|
10
|
+
this._type = type;
|
|
11
|
+
this._otherColumn = otherColumn;
|
|
12
|
+
}
|
|
13
|
+
and(condition) {
|
|
14
|
+
return new QueryConditionChain(this, condition, "and");
|
|
15
|
+
}
|
|
16
|
+
or(condition) {
|
|
17
|
+
return new QueryConditionChain(this, condition, "or");
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
QueryJoinCondition as default
|
|
22
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import JoinedTables from "./joined-tables";
|
|
2
|
+
class JoinedTablesChain {
|
|
3
|
+
constructor(_table, _modifier, _parent) {
|
|
4
|
+
this._table = _table;
|
|
5
|
+
this._modifier = _modifier;
|
|
6
|
+
this._parent = _parent;
|
|
7
|
+
}
|
|
8
|
+
on(condition) {
|
|
9
|
+
return new JoinedTables(condition, this);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
JoinedTablesChain as default
|
|
14
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import JoinedTablesChain from "./joined-tables-chain";
|
|
2
|
+
class JoinedTables {
|
|
3
|
+
constructor(_condition, _parent) {
|
|
4
|
+
this._condition = _condition;
|
|
5
|
+
this._parent = _parent;
|
|
6
|
+
}
|
|
7
|
+
innerJoin(table) {
|
|
8
|
+
return new JoinedTablesChain(table, "inner", this);
|
|
9
|
+
}
|
|
10
|
+
leftJoin(table) {
|
|
11
|
+
return new JoinedTablesChain(table, "left", this);
|
|
12
|
+
}
|
|
13
|
+
rightJoin(table) {
|
|
14
|
+
return new JoinedTablesChain(table, "right", this);
|
|
15
|
+
}
|
|
16
|
+
fullJoin(table) {
|
|
17
|
+
return new JoinedTablesChain(table, "full", this);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
JoinedTables as default
|
|
22
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
class QueryOrdering {
|
|
2
|
+
_column;
|
|
3
|
+
_direction;
|
|
4
|
+
_nullsPosition;
|
|
5
|
+
constructor(column, direction) {
|
|
6
|
+
this._column = column;
|
|
7
|
+
this._direction = direction;
|
|
8
|
+
}
|
|
9
|
+
nullsFirst() {
|
|
10
|
+
this._nullsPosition = "FIRST";
|
|
11
|
+
return this;
|
|
12
|
+
}
|
|
13
|
+
nullsLast() {
|
|
14
|
+
this._nullsPosition = "LAST";
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
QueryOrdering as default
|
|
20
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
class SelectQuery {
|
|
2
|
+
constructor(_queryProcessor, _tables) {
|
|
3
|
+
this._queryProcessor = _queryProcessor;
|
|
4
|
+
this._tables = _tables;
|
|
5
|
+
}
|
|
6
|
+
_distinct = false;
|
|
7
|
+
_offset;
|
|
8
|
+
_limit;
|
|
9
|
+
_conditions = [];
|
|
10
|
+
_groupBy = [];
|
|
11
|
+
_having = [];
|
|
12
|
+
_orderings = [];
|
|
13
|
+
_columns = [];
|
|
14
|
+
_action;
|
|
15
|
+
offset(offset) {
|
|
16
|
+
this._offset = offset;
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
limit(limit) {
|
|
20
|
+
this._limit = limit;
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
distinct() {
|
|
24
|
+
this._distinct = true;
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
where(...conditions) {
|
|
28
|
+
this._conditions = conditions;
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
groupBy(...columns) {
|
|
32
|
+
this._groupBy = columns;
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
having(...conditions) {
|
|
36
|
+
this._having = conditions;
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
orderBy(...orderings) {
|
|
40
|
+
this._orderings = orderings;
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
select(...columns) {
|
|
44
|
+
this._columns = columns;
|
|
45
|
+
this._action = "select";
|
|
46
|
+
return this._queryProcessor(this);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
SelectQuery as default
|
|
51
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
class TableConditionQuery {
|
|
2
|
+
constructor(_queryProcessor, _table, _conditions) {
|
|
3
|
+
this._queryProcessor = _queryProcessor;
|
|
4
|
+
this._table = _table;
|
|
5
|
+
this._conditions = _conditions;
|
|
6
|
+
}
|
|
7
|
+
_columns = [];
|
|
8
|
+
_action;
|
|
9
|
+
_entity;
|
|
10
|
+
update(entity) {
|
|
11
|
+
this._entity = entity;
|
|
12
|
+
this._action = "update";
|
|
13
|
+
return this._queryProcessor(this);
|
|
14
|
+
}
|
|
15
|
+
delete() {
|
|
16
|
+
this._action = "delete";
|
|
17
|
+
return this._queryProcessor(this);
|
|
18
|
+
}
|
|
19
|
+
count() {
|
|
20
|
+
this._columns = [this._table.$all.count()];
|
|
21
|
+
this._action = "select";
|
|
22
|
+
return this._queryProcessor(this).then((rows) => rows[0]);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
TableConditionQuery as default
|
|
27
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import TableConditionQuery from "./table-condition-query";
|
|
2
|
+
import ValueColumn from "../column/value-column";
|
|
3
|
+
class TableQuery {
|
|
4
|
+
constructor(_queryProcessor, _table) {
|
|
5
|
+
this._queryProcessor = _queryProcessor;
|
|
6
|
+
this._table = _table;
|
|
7
|
+
}
|
|
8
|
+
_entity;
|
|
9
|
+
_action;
|
|
10
|
+
_columns = [];
|
|
11
|
+
where(...conditions) {
|
|
12
|
+
return new TableConditionQuery(this._queryProcessor, this._table, conditions);
|
|
13
|
+
}
|
|
14
|
+
insert(param) {
|
|
15
|
+
this._entity = param;
|
|
16
|
+
this._action = "insert";
|
|
17
|
+
return this._queryProcessor(this);
|
|
18
|
+
}
|
|
19
|
+
deleteAll() {
|
|
20
|
+
this._action = "delete";
|
|
21
|
+
return this._queryProcessor(this);
|
|
22
|
+
}
|
|
23
|
+
updateAll(entity) {
|
|
24
|
+
this._entity = entity;
|
|
25
|
+
this._action = "update";
|
|
26
|
+
return this._queryProcessor(this);
|
|
27
|
+
}
|
|
28
|
+
countAll() {
|
|
29
|
+
this._columns = [this._table.$all.count()];
|
|
30
|
+
this._action = "select";
|
|
31
|
+
return this._queryProcessor(this).then((rows) => rows[0]);
|
|
32
|
+
}
|
|
33
|
+
delete(id) {
|
|
34
|
+
return this._whereId(id).delete().then((count) => count > 0);
|
|
35
|
+
}
|
|
36
|
+
update(id, entity) {
|
|
37
|
+
return this._whereId(id).update(entity).then((count) => count > 0);
|
|
38
|
+
}
|
|
39
|
+
get(id) {
|
|
40
|
+
let query = this._whereId(id);
|
|
41
|
+
return this._queryProcessor({ _action: "select", ...query }).then((rows) => rows[0]);
|
|
42
|
+
}
|
|
43
|
+
_whereId(id) {
|
|
44
|
+
let $id = this._table.$id;
|
|
45
|
+
if ($id instanceof ValueColumn) {
|
|
46
|
+
return this.where($id.eq(id));
|
|
47
|
+
} else {
|
|
48
|
+
return this.where(...Object.keys($id).map((key) => this._table[key].eq(id[key])));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
TableQuery as default
|
|
54
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import SelectQuery from "./query/select-query";
|
|
2
|
+
import TableQuery from "./query/table-query";
|
|
3
|
+
class QuerySource {
|
|
4
|
+
constructor(_queryProcessor) {
|
|
5
|
+
this._queryProcessor = _queryProcessor;
|
|
6
|
+
}
|
|
7
|
+
from(table1, table2, table3) {
|
|
8
|
+
if (table3 != null) return new SelectQuery(this._queryProcessor, [table1, table2, table3]);
|
|
9
|
+
else if (table2 != null) return new SelectQuery(this._queryProcessor, [table1, table2]);
|
|
10
|
+
return new SelectQuery(this._queryProcessor, [table1]);
|
|
11
|
+
}
|
|
12
|
+
table(table) {
|
|
13
|
+
return new TableQuery(this._queryProcessor, table);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
QuerySource as default
|
|
18
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import BasicColumn from "./column/basic-column";
|
|
2
|
+
import JoinedTablesChain from "./join/joined-tables-chain";
|
|
3
|
+
class QueryTable {
|
|
4
|
+
constructor(_$name) {
|
|
5
|
+
this._$name = _$name;
|
|
6
|
+
}
|
|
7
|
+
_$type;
|
|
8
|
+
_$idType;
|
|
9
|
+
// abstract readonly $id; // FIXME I got a dozen incomprehensible type errors
|
|
10
|
+
$all = new BasicColumn(this, "*");
|
|
11
|
+
innerJoin(table) {
|
|
12
|
+
return new JoinedTablesChain(table, "inner", this);
|
|
13
|
+
}
|
|
14
|
+
leftJoin(table) {
|
|
15
|
+
return new JoinedTablesChain(table, "left", this);
|
|
16
|
+
}
|
|
17
|
+
rightJoin(table) {
|
|
18
|
+
return new JoinedTablesChain(table, "right", this);
|
|
19
|
+
}
|
|
20
|
+
fullJoin(table) {
|
|
21
|
+
return new JoinedTablesChain(table, "full", this);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
var query_table_default = QueryTable;
|
|
25
|
+
export {
|
|
26
|
+
query_table_default as default
|
|
27
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import QuerySource from "../builder/query-source";
|
|
2
|
+
import { createQueryProcessor } from "./query-processor";
|
|
3
|
+
class MySqlQuerySource extends QuerySource {
|
|
4
|
+
constructor(client, options = {}) {
|
|
5
|
+
super(createQueryProcessor(client, options, "mysql"));
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
MySqlQuerySource as default
|
|
10
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import QuerySource from "../builder/query-source";
|
|
2
|
+
import { createQueryProcessor } from "./query-processor";
|
|
3
|
+
class PgQuerySource extends QuerySource {
|
|
4
|
+
constructor(client, options = {}) {
|
|
5
|
+
super(createQueryProcessor(client, options, "pg"));
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
PgQuerySource as default
|
|
10
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Log } from "ng2-logger/lib-prod";
|
|
2
|
+
import { convertQueryToParameterizedSQL } from "../converter/parameterized-converter";
|
|
3
|
+
import { convertQueryToSQL } from "../converter/sql-converter";
|
|
4
|
+
const log = Log.create(
|
|
5
|
+
"query processor"
|
|
6
|
+
// Level.__NOTHING
|
|
7
|
+
);
|
|
8
|
+
const DEFAULT_OPTIONS = {
|
|
9
|
+
lineBreaks: false,
|
|
10
|
+
parameterized: true,
|
|
11
|
+
logging: true,
|
|
12
|
+
identifierQuote: '"'
|
|
13
|
+
};
|
|
14
|
+
function mySqlTypeCast(field, next) {
|
|
15
|
+
if (field.type == "TINY" && field.length == 1) {
|
|
16
|
+
let value = field.string();
|
|
17
|
+
if (value == "1") return true;
|
|
18
|
+
if (value == "0") return false;
|
|
19
|
+
return null;
|
|
20
|
+
} else if (field.type == "JSON") {
|
|
21
|
+
let value = field.string();
|
|
22
|
+
return value == null ? null : JSON.parse(value);
|
|
23
|
+
}
|
|
24
|
+
return next();
|
|
25
|
+
}
|
|
26
|
+
function createQueryProcessor(client, _options = {}, engine = "pg") {
|
|
27
|
+
let options = Object.assign({}, DEFAULT_OPTIONS, _options);
|
|
28
|
+
let queryOptions = {
|
|
29
|
+
lineBreak: options.lineBreaks ? "\n" : " ",
|
|
30
|
+
nameEscape: _options.identifierQuote || (engine === "mysql" ? "`" : '"')
|
|
31
|
+
};
|
|
32
|
+
return (query) => {
|
|
33
|
+
if (options.parameterized) {
|
|
34
|
+
let { sql, params } = convertQueryToParameterizedSQL(query, queryOptions, engine);
|
|
35
|
+
return client.query(sql, params);
|
|
36
|
+
} else {
|
|
37
|
+
let sql = convertQueryToSQL(query, queryOptions, engine);
|
|
38
|
+
return client.query(sql, void 0);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export {
|
|
43
|
+
createQueryProcessor
|
|
44
|
+
};
|