taon-type-sql 21.0.22 → 21.0.24

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.
Files changed (82) hide show
  1. package/browser/package.json +1 -1
  2. package/browser-prod/package.json +1 -1
  3. package/lib/build-info._auto-generated_.d.ts +1 -1
  4. package/lib/build-info._auto-generated_.js +1 -1
  5. package/lib/package.json +1 -1
  6. package/lib-prod/{build-info._auto-generated_.ts → build-info._auto-generated_.js} +1 -2
  7. package/lib-prod/builder/column/{basic-column.ts → basic-column.js} +4 -10
  8. package/lib-prod/builder/column/boolean-column.js +11 -0
  9. package/lib-prod/builder/column/comparable-column.js +39 -0
  10. package/lib-prod/builder/column/date-column.js +11 -0
  11. package/lib-prod/builder/column/number-column.js +16 -0
  12. package/lib-prod/builder/column/query-column.js +18 -0
  13. package/lib-prod/builder/column/string-column.js +33 -0
  14. package/lib-prod/builder/column/value-column.js +27 -0
  15. package/lib-prod/builder/condition/query-column-condition.js +16 -0
  16. package/lib-prod/builder/condition/query-condition-chain.js +26 -0
  17. package/lib-prod/builder/condition/query-condition.js +4 -0
  18. package/lib-prod/builder/condition/query-join-condition.js +16 -0
  19. package/lib-prod/builder/helpers/{generics-helper.ts → generics-helper.js} +2 -1
  20. package/lib-prod/builder/helpers/internal-types.js +1 -0
  21. package/lib-prod/builder/join/joined-tables-chain.js +11 -0
  22. package/lib-prod/builder/join/joined-tables.js +19 -0
  23. package/lib-prod/builder/other/query-ordering.js +14 -0
  24. package/lib-prod/builder/query/select-query.js +45 -0
  25. package/lib-prod/builder/query/table-condition-query.js +22 -0
  26. package/lib-prod/builder/query/table-query.js +52 -0
  27. package/lib-prod/builder/query-source.js +17 -0
  28. package/lib-prod/builder/query-table.js +22 -0
  29. package/lib-prod/client/{mysql.ts → mysql.js} +3 -5
  30. package/lib-prod/client/{pg.ts → pg.js} +3 -5
  31. package/lib-prod/client/query-processor.js +69 -0
  32. package/lib-prod/converter/{param-converter.ts → param-converter.js} +11 -8
  33. package/lib-prod/converter/parameterized-converter.js +14 -0
  34. package/lib-prod/converter/{query-converter.ts → query-converter.js} +94 -110
  35. package/lib-prod/converter/result-converter.js +85 -0
  36. package/lib-prod/converter/sql-converter.js +5 -0
  37. package/lib-prod/converter/type-converter.js +36 -0
  38. package/lib-prod/converter/types.js +1 -0
  39. package/lib-prod/env/{env.angular-node-app.ts → env.angular-node-app.js} +1 -1
  40. package/lib-prod/env/{env.docs-webapp.ts → env.docs-webapp.js} +1 -1
  41. package/lib-prod/env/{env.electron-app.ts → env.electron-app.js} +1 -1
  42. package/lib-prod/env/{env.mobile-app.ts → env.mobile-app.js} +1 -1
  43. package/lib-prod/env/{env.npm-lib-and-cli-tool.ts → env.npm-lib-and-cli-tool.js} +1 -1
  44. package/lib-prod/env/{env.vscode-plugin.ts → env.vscode-plugin.js} +1 -1
  45. package/lib-prod/{index._auto-generated_.ts → index._auto-generated_.js} +1 -1
  46. package/lib-prod/{index.ts → index.js} +0 -12
  47. package/lib-prod/migrations/index.js +2 -0
  48. package/lib-prod/migrations/{migrations_index._auto-generated_.ts → migrations_index._auto-generated_.js} +0 -2
  49. package/lib-prod/package.json +1 -1
  50. package/package.json +1 -1
  51. package/websql/package.json +1 -1
  52. package/websql-prod/package.json +1 -1
  53. package/lib-prod/builder/column/boolean-column.ts +0 -19
  54. package/lib-prod/builder/column/comparable-column.ts +0 -56
  55. package/lib-prod/builder/column/date-column.ts +0 -19
  56. package/lib-prod/builder/column/number-column.ts +0 -25
  57. package/lib-prod/builder/column/query-column.ts +0 -34
  58. package/lib-prod/builder/column/string-column.ts +0 -47
  59. package/lib-prod/builder/column/value-column.ts +0 -39
  60. package/lib-prod/builder/condition/query-column-condition.ts +0 -28
  61. package/lib-prod/builder/condition/query-condition-chain.ts +0 -42
  62. package/lib-prod/builder/condition/query-condition.ts +0 -13
  63. package/lib-prod/builder/condition/query-join-condition.ts +0 -27
  64. package/lib-prod/builder/helpers/internal-types.ts +0 -31
  65. package/lib-prod/builder/join/joined-tables-chain.ts +0 -17
  66. package/lib-prod/builder/join/joined-tables.ts +0 -28
  67. package/lib-prod/builder/other/query-ordering.ts +0 -26
  68. package/lib-prod/builder/query/select-query.ts +0 -68
  69. package/lib-prod/builder/query/table-condition-query.ts +0 -35
  70. package/lib-prod/builder/query/table-query.ts +0 -72
  71. package/lib-prod/builder/query-source.ts +0 -25
  72. package/lib-prod/builder/query-table.ts +0 -34
  73. package/lib-prod/client/query-processor.ts +0 -89
  74. package/lib-prod/converter/parameterized-converter.ts +0 -20
  75. package/lib-prod/converter/result-converter.ts +0 -88
  76. package/lib-prod/converter/sql-converter.ts +0 -7
  77. package/lib-prod/converter/type-converter.ts +0 -29
  78. package/lib-prod/converter/types.ts +0 -6
  79. package/lib-prod/lib-info.md +0 -8
  80. package/lib-prod/migrations/index.ts +0 -2
  81. package/lib-prod/migrations/migrations-info.md +0 -6
  82. /package/lib-prod/env/{index.ts → index.js} +0 -0
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "taon-type-sql/browser",
3
- "version": "21.0.22",
3
+ "version": "21.0.24",
4
4
  "peerDependencies": {
5
5
  "@angular/common": "^21.0.0",
6
6
  "@angular/core": "^21.0.0"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "taon-type-sql/browser-prod",
3
- "version": "21.0.22",
3
+ "version": "21.0.24",
4
4
  "peerDependencies": {
5
5
  "@angular/common": "^21.0.0",
6
6
  "@angular/core": "^21.0.0"
@@ -21,4 +21,4 @@ export declare const CURRENT_PACKAGE_TAON_VERSION = "v21";
21
21
  /**
22
22
  * Autogenerated by current cli tool. Use *tnp release* to bump version.
23
23
  */
24
- export declare const CURRENT_PACKAGE_VERSION = "21.0.22";
24
+ export declare const CURRENT_PACKAGE_VERSION = "21.0.24";
@@ -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.22';
28
+ exports.CURRENT_PACKAGE_VERSION = '21.0.24';
29
29
  // THIS FILE IS GENERATED - DO NOT MODIFY
30
30
  //# sourceMappingURL=build-info._auto-generated_.js.map
package/lib/package.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "taon-type-sql/lib",
3
- "version": "21.0.22"
3
+ "version": "21.0.24"
4
4
  }
@@ -22,6 +22,5 @@ export const CURRENT_PACKAGE_TAON_VERSION = 'v21';
22
22
  /**
23
23
  * Autogenerated by current cli tool. Use *tnp release* to bump version.
24
24
  */
25
- export const CURRENT_PACKAGE_VERSION = '21.0.22';
25
+ export const CURRENT_PACKAGE_VERSION = '21.0.24';
26
26
  // THIS FILE IS GENERATED - DO NOT MODIFY
27
-
@@ -1,17 +1,11 @@
1
- import QueryTable from "../query-table";
2
1
  import QueryColumn from "./query-column";
3
2
  import NumberColumn from "./number-column";
4
- import {ColumnModifier, ColumnName} from "../helpers/internal-types";
5
-
6
3
  // This file is only needed because the QueryColumn can't implement its count method b. of circular dependencies
7
-
8
- export default class BasicColumn<Table extends QueryTable<any, any>, T> extends QueryColumn<Table, T> {
9
-
10
- constructor(table: Table, name: ColumnName, modifiers: ColumnModifier[] = []) {
4
+ export default class BasicColumn extends QueryColumn {
5
+ constructor(table, name, modifiers = []) {
11
6
  super(table, name, modifiers);
12
7
  }
13
-
14
- count(): NumberColumn<Table> {
8
+ count() {
15
9
  return new NumberColumn(this._table, this._name, this._modifiers.concat({ name: 'count' }));
16
10
  }
17
- }
11
+ }
@@ -0,0 +1,11 @@
1
+ import NumberColumn from "./number-column";
2
+ import ValueColumn from "./value-column";
3
+ export default class BooleanColumn extends ValueColumn {
4
+ constructor(table, name, modifiers = []) {
5
+ super(table, name, modifiers);
6
+ this._type = 'boolean';
7
+ }
8
+ count() {
9
+ return new NumberColumn(this._table, this._name, this._modifiers.concat({ name: 'count' }));
10
+ }
11
+ }
@@ -0,0 +1,39 @@
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
+ export default ComparableColumn;
@@ -0,0 +1,11 @@
1
+ import ComparableColumn from "./comparable-column";
2
+ import NumberColumn from "./number-column";
3
+ export default class DateColumn extends ComparableColumn {
4
+ constructor(table, name, modifiers = []) {
5
+ super(table, name, modifiers);
6
+ this._type = 'date';
7
+ }
8
+ count() {
9
+ return new NumberColumn(this._table, this._name, this._modifiers.concat({ name: 'count' }));
10
+ }
11
+ }
@@ -0,0 +1,16 @@
1
+ import ComparableColumn from "./comparable-column";
2
+ export default class NumberColumn extends ComparableColumn {
3
+ constructor(table, name, modifiers = []) {
4
+ super(table, name, modifiers);
5
+ this._type = 'number';
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
+ }
@@ -0,0 +1,18 @@
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
+ as(alias) {
9
+ return new this.constructor(this._table, this._name, this._modifiers.concat({ name: 'as', params: alias }));
10
+ }
11
+ isNull() {
12
+ return new QueryColumnCondition(this, 'is-null');
13
+ }
14
+ isNotNull() {
15
+ return new QueryColumnCondition(this, 'is-not-null');
16
+ }
17
+ }
18
+ export default QueryColumn;
@@ -0,0 +1,33 @@
1
+ import ComparableColumn from "./comparable-column";
2
+ import NumberColumn from "./number-column";
3
+ import QueryColumnCondition from "../condition/query-column-condition";
4
+ export default class StringColumn extends ComparableColumn {
5
+ constructor(table, name, modifiers = []) {
6
+ super(table, name, modifiers);
7
+ this._type = 'string';
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
+ }
@@ -0,0 +1,27 @@
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
+ }
19
+ else {
20
+ return new QueryColumnCondition(this, 'eq', value);
21
+ }
22
+ }
23
+ ne(value) {
24
+ return new QueryColumnCondition(this, 'ne', value);
25
+ }
26
+ }
27
+ export default ValueColumn;
@@ -0,0 +1,16 @@
1
+ import QueryCondition from "./query-condition";
2
+ import QueryConditionChain from "./query-condition-chain";
3
+ export default class QueryColumnCondition extends QueryCondition {
4
+ constructor(column, type, ...values) {
5
+ super();
6
+ this._column = column;
7
+ this._type = type;
8
+ this._values = values;
9
+ }
10
+ and(condition) {
11
+ return new QueryConditionChain(this, condition, 'and');
12
+ }
13
+ or(condition) {
14
+ return new QueryConditionChain(this, condition, 'or');
15
+ }
16
+ }
@@ -0,0 +1,26 @@
1
+ import QueryCondition from "./query-condition";
2
+ export default class QueryConditionChain extends QueryCondition {
3
+ constructor(sibling, child, chainType) {
4
+ super();
5
+ this._parenthesis = false;
6
+ this._negation = false;
7
+ this._sibling = sibling;
8
+ this._child = child;
9
+ this._chainType = chainType;
10
+ }
11
+ // TODO how to call this
12
+ $() {
13
+ this._parenthesis = true;
14
+ return this;
15
+ }
16
+ not() {
17
+ this._negation = true;
18
+ return this;
19
+ }
20
+ and(condition) {
21
+ return new QueryConditionChain(this, condition, 'and');
22
+ }
23
+ or(condition) {
24
+ return new QueryConditionChain(this, condition, 'or');
25
+ }
26
+ }
@@ -0,0 +1,4 @@
1
+ // TODO I had to copy-paste the method implementations to every child class to avoid circular dependencies
2
+ class QueryCondition {
3
+ }
4
+ export default QueryCondition;
@@ -0,0 +1,16 @@
1
+ import QueryCondition from "./query-condition";
2
+ import QueryConditionChain from "./query-condition-chain";
3
+ export default class QueryJoinCondition extends QueryCondition {
4
+ constructor(column, type, otherColumn) {
5
+ super();
6
+ this._column = column;
7
+ this._type = type;
8
+ this._otherColumn = otherColumn;
9
+ }
10
+ and(condition) {
11
+ return new QueryConditionChain(this, condition, 'and');
12
+ }
13
+ or(condition) {
14
+ return new QueryConditionChain(this, condition, 'or');
15
+ }
16
+ }
@@ -1,2 +1,3 @@
1
1
  // TODO In TS generic parameters not used in the class are not enforced, so I have to add dummy fields that use them. Replace with nominal typing
2
- export default class GenericsHelper<T> {}
2
+ export default class GenericsHelper {
3
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ import JoinedTables from "./joined-tables";
2
+ export default 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
+ }
@@ -0,0 +1,19 @@
1
+ import JoinedTablesChain from "./joined-tables-chain";
2
+ export default 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
+ }
@@ -0,0 +1,14 @@
1
+ export default class QueryOrdering {
2
+ constructor(column, direction) {
3
+ this._column = column;
4
+ this._direction = direction;
5
+ }
6
+ nullsFirst() {
7
+ this._nullsPosition = 'FIRST';
8
+ return this;
9
+ }
10
+ nullsLast() {
11
+ this._nullsPosition = 'LAST';
12
+ return this;
13
+ }
14
+ }
@@ -0,0 +1,45 @@
1
+ export default class SelectQuery {
2
+ constructor(_queryProcessor, _tables) {
3
+ this._queryProcessor = _queryProcessor;
4
+ this._tables = _tables;
5
+ this._distinct = false;
6
+ this._conditions = [];
7
+ this._groupBy = [];
8
+ this._having = [];
9
+ this._orderings = [];
10
+ this._columns = [];
11
+ }
12
+ offset(offset) {
13
+ this._offset = offset;
14
+ return this;
15
+ }
16
+ limit(limit) {
17
+ this._limit = limit;
18
+ return this;
19
+ }
20
+ distinct() {
21
+ this._distinct = true;
22
+ return this;
23
+ }
24
+ where(...conditions) {
25
+ this._conditions = conditions;
26
+ return this;
27
+ }
28
+ groupBy(...columns) {
29
+ this._groupBy = columns;
30
+ return this;
31
+ }
32
+ having(...conditions) {
33
+ this._having = conditions;
34
+ return this;
35
+ }
36
+ orderBy(...orderings) {
37
+ this._orderings = orderings;
38
+ return this;
39
+ }
40
+ select(...columns) {
41
+ this._columns = columns;
42
+ this._action = 'select';
43
+ return this._queryProcessor(this);
44
+ }
45
+ }
@@ -0,0 +1,22 @@
1
+ export default class TableConditionQuery {
2
+ constructor(_queryProcessor, _table, _conditions) {
3
+ this._queryProcessor = _queryProcessor;
4
+ this._table = _table;
5
+ this._conditions = _conditions;
6
+ this._columns = [];
7
+ }
8
+ update(entity) {
9
+ this._entity = entity;
10
+ this._action = 'update';
11
+ return this._queryProcessor(this);
12
+ }
13
+ delete() {
14
+ this._action = 'delete';
15
+ return this._queryProcessor(this);
16
+ }
17
+ count() {
18
+ this._columns = [this._table.$all.count()];
19
+ this._action = 'select';
20
+ return this._queryProcessor(this).then((rows) => rows[0]);
21
+ }
22
+ }
@@ -0,0 +1,52 @@
1
+ import TableConditionQuery from "./table-condition-query";
2
+ import ValueColumn from "../column/value-column";
3
+ export default class TableQuery {
4
+ constructor(_queryProcessor, _table) {
5
+ this._queryProcessor = _queryProcessor;
6
+ this._table = _table;
7
+ this._columns = [];
8
+ }
9
+ where(...conditions) {
10
+ return new TableConditionQuery(this._queryProcessor, this._table, conditions);
11
+ }
12
+ insert(param) {
13
+ this._entity = param;
14
+ this._action = 'insert';
15
+ return this._queryProcessor(this);
16
+ }
17
+ deleteAll() {
18
+ this._action = 'delete';
19
+ return this._queryProcessor(this);
20
+ }
21
+ updateAll(entity) {
22
+ this._entity = entity;
23
+ this._action = 'update';
24
+ return this._queryProcessor(this);
25
+ }
26
+ countAll() {
27
+ this._columns = [this._table.$all.count()];
28
+ this._action = 'select';
29
+ return this._queryProcessor(this).then((rows) => rows[0]);
30
+ }
31
+ delete(id) {
32
+ return this._whereId(id).delete().then(count => count > 0);
33
+ }
34
+ update(id, entity) {
35
+ return this._whereId(id).update(entity).then(count => count > 0);
36
+ }
37
+ get(id) {
38
+ let query = this._whereId(id);
39
+ return this._queryProcessor({ _action: 'select', ...query })
40
+ .then((rows) => rows[0]);
41
+ }
42
+ _whereId(id) {
43
+ // TODO remove assertions if $id typing is fixed
44
+ let $id = this._table.$id;
45
+ if ($id instanceof ValueColumn) {
46
+ return this.where($id.eq(id));
47
+ }
48
+ else {
49
+ return this.where(...Object.keys($id).map(key => this._table[key].eq(id[key])));
50
+ }
51
+ }
52
+ }
@@ -0,0 +1,17 @@
1
+ import SelectQuery from './query/select-query';
2
+ import TableQuery from "./query/table-query";
3
+ export default class QuerySource {
4
+ constructor(_queryProcessor) {
5
+ this._queryProcessor = _queryProcessor;
6
+ }
7
+ from(table1, table2, table3) {
8
+ if (table3 != null)
9
+ return new SelectQuery(this._queryProcessor, [table1, table2, table3]);
10
+ else if (table2 != null)
11
+ return new SelectQuery(this._queryProcessor, [table1, table2]);
12
+ return new SelectQuery(this._queryProcessor, [table1]);
13
+ }
14
+ table(table) {
15
+ return new TableQuery(this._queryProcessor, table);
16
+ }
17
+ }
@@ -0,0 +1,22 @@
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
+ // abstract readonly $id; // FIXME I got a dozen incomprehensible type errors
7
+ this.$all = new BasicColumn(this, '*');
8
+ }
9
+ innerJoin(table) {
10
+ return new JoinedTablesChain(table, 'inner', this);
11
+ }
12
+ leftJoin(table) {
13
+ return new JoinedTablesChain(table, 'left', this);
14
+ }
15
+ rightJoin(table) {
16
+ return new JoinedTablesChain(table, 'right', this);
17
+ }
18
+ fullJoin(table) {
19
+ return new JoinedTablesChain(table, 'full', this);
20
+ }
21
+ }
22
+ export default QueryTable;
@@ -1,9 +1,7 @@
1
1
  import QuerySource from "../builder/query-source";
2
- import {QueryProcessorOptions, createQueryProcessor} from "./query-processor";
3
-
2
+ import { createQueryProcessor } from "./query-processor";
4
3
  export default class MySqlQuerySource extends QuerySource {
5
-
6
- constructor(client: any, options: QueryProcessorOptions = {}) {
4
+ constructor(client, options = {}) {
7
5
  super(createQueryProcessor(client, options, 'mysql'));
8
6
  }
9
- }
7
+ }
@@ -1,9 +1,7 @@
1
1
  import QuerySource from "../builder/query-source";
2
- import {QueryProcessorOptions, createQueryProcessor} from "./query-processor";
3
-
2
+ import { createQueryProcessor } from "./query-processor";
4
3
  export default class PgQuerySource extends QuerySource {
5
-
6
- constructor(client: any, options: QueryProcessorOptions = {}) {
4
+ constructor(client, options = {}) {
7
5
  super(createQueryProcessor(client, options, 'pg'));
8
6
  }
9
- }
7
+ }
@@ -0,0 +1,69 @@
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('query processor');
5
+ const DEFAULT_OPTIONS = {
6
+ lineBreaks: false,
7
+ parameterized: true,
8
+ logging: true,
9
+ identifierQuote: '"'
10
+ };
11
+ function mySqlTypeCast(field, next) {
12
+ if (field.type == 'TINY' && field.length == 1) { // Boolean
13
+ let value = field.string();
14
+ if (value == '1')
15
+ return true;
16
+ if (value == '0')
17
+ return false;
18
+ return null;
19
+ }
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
+ export 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
+ // function processSql(query: any, sql: string, params: any[] | undefined, callback: any): Promise<any> {
33
+ // if (options.logging) log.i(sql);
34
+ // if (options.logger) options.logger(sql, params);
35
+ // return new Promise((resolve, reject) => {
36
+ // callback(sql, params, (err: any, result: any) => {
37
+ // if (err) reject(err);
38
+ // else resolve(convertResult(query, result, engine));
39
+ // });
40
+ // });
41
+ // }
42
+ // function executeSql(sql: string, params: any[] | undefined, cb: any) {
43
+ // if (engine === 'pg') {
44
+ // client.query(sql, params || cb, params ? cb : undefined);
45
+ // } else if (engine === 'mysql') {
46
+ // client.query({
47
+ // sql,
48
+ // values: params,
49
+ // typeCast: mySqlTypeCast
50
+ // }, cb);
51
+ // } else throw new Error('Unknown DB engine: ' + engine);
52
+ // }
53
+ return (query) => {
54
+ if (options.parameterized) {
55
+ let { sql, params } = convertQueryToParameterizedSQL(query, queryOptions, engine);
56
+ // if (Helpers.isWebSQL || Helpers.isNode) {
57
+ return client.query(sql, params);
58
+ // }
59
+ // return processSql(query, sql, params, (sql: string, params: any[], cb: any) => executeSql(sql, params, cb));
60
+ }
61
+ else {
62
+ let sql = convertQueryToSQL(query, queryOptions, engine);
63
+ // if (Helpers.isWebSQL || Helpers.isNode) {
64
+ return client.query(sql, undefined);
65
+ // }
66
+ // return processSql(query, sql, undefined, (sql: string, params: undefined, cb: any) => executeSql(sql, undefined, cb));
67
+ }
68
+ };
69
+ }
@@ -1,23 +1,26 @@
1
- export function convertSubstitutionParam(param: any): string {
2
- if (param == null) return 'NULL';
1
+ export function convertSubstitutionParam(param) {
2
+ if (param == null)
3
+ return 'NULL';
3
4
  if (typeof param === 'string' || param instanceof String) {
4
5
  return `'${String(param)}'`;
5
- } else if (typeof param === 'boolean' || param instanceof Boolean) {
6
+ }
7
+ else if (typeof param === 'boolean' || param instanceof Boolean) {
6
8
  return String(param).toUpperCase();
7
- } else if (param instanceof Date) {
9
+ }
10
+ else if (param instanceof Date) {
8
11
  return `'${param.toISOString()}'`;
9
- } else if (typeof param === 'number' || param instanceof Number) {
12
+ }
13
+ else if (typeof param === 'number' || param instanceof Number) {
10
14
  return String(param);
11
15
  }
12
16
  return `'${JSON.stringify(param)}'`;
13
17
  }
14
-
15
18
  // node mysql doesn't have an typeCast equivalent solution for the other direction
16
19
  // node-postgres: https://github.com/brianc/node-postgres/issues/442
17
- export function convertEscapedParam(param: any) {
20
+ export function convertEscapedParam(param) {
18
21
  if (typeof param === 'object' && !(param == null || param instanceof String || param instanceof Number ||
19
22
  param instanceof Boolean || param instanceof Date)) {
20
23
  return JSON.stringify(param);
21
24
  }
22
25
  return param;
23
- }
26
+ }