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,19 +0,0 @@
1
- import QueryTable from "../query-table";
2
- import NumberColumn from "./number-column";
3
- import ValueColumn from "./value-column";
4
- import {ColumnModifier, ColumnName} from "../helpers/internal-types";
5
-
6
-
7
- export default class BooleanColumn<Table extends QueryTable<any, any>> extends ValueColumn<Table, boolean> {
8
-
9
- protected _type = 'boolean';
10
-
11
- constructor(table: Table, name: ColumnName, modifiers: ColumnModifier[] = []) {
12
- super(table, name, modifiers);
13
- }
14
-
15
- count(): NumberColumn<Table> {
16
- return new NumberColumn(this._table, this._name, this._modifiers.concat({ name: 'count' }));
17
- }
18
-
19
- }
@@ -1,56 +0,0 @@
1
- import QueryColumnCondition from "../condition/query-column-condition";
2
- import QueryTable from "../query-table";
3
- import ValueColumn from "./value-column";
4
- import {ColumnModifier, ColumnName} from "../helpers/internal-types";
5
-
6
-
7
- abstract class ComparableColumn<Table extends QueryTable<any, any>, T> extends ValueColumn<Table, T> {
8
-
9
- constructor(table: Table, name: ColumnName, modifiers: ColumnModifier[] = []) {
10
- super(table, name, modifiers);
11
- }
12
-
13
- lt(value: T) {
14
- return new QueryColumnCondition<Table, T>(this, 'lt', value);
15
- }
16
-
17
- gt(value: T) {
18
- return new QueryColumnCondition<Table, T>(this, 'gt', value);
19
- }
20
-
21
- lte(value: T) {
22
- return new QueryColumnCondition<Table, T>(this, 'lte', value);
23
- }
24
-
25
- gte(value: T) {
26
- return new QueryColumnCondition<Table, T>(this, 'gte', value);
27
- }
28
-
29
- in(values: T[]) {
30
- return new QueryColumnCondition<Table, T>(this, 'in', ...values);
31
- }
32
-
33
- notIn(values: T[]) {
34
- return new QueryColumnCondition<Table, T>(this, 'not-in', ...values);
35
- }
36
-
37
- between(value1: T, value2: T) {
38
- return new QueryColumnCondition<Table, T>(this, 'between', value1, value2);
39
- }
40
-
41
- notBetween(value1: T, value2: T) {
42
- return new QueryColumnCondition<Table, T>(this, 'not-between', value1, value2);
43
- }
44
-
45
- // min/max exists for text columns too, not just numeric and date
46
-
47
- min(): this {
48
- return new (<any>this.constructor)(this._table, this._name, this._modifiers.concat({ name: 'min' }));
49
- }
50
-
51
- max(): this {
52
- return new (<any>this.constructor)(this._table, this._name, this._modifiers.concat({ name: 'max' }));
53
- }
54
- }
55
-
56
- export default ComparableColumn;
@@ -1,19 +0,0 @@
1
- import QueryTable from "../query-table";
2
- import ComparableColumn from "./comparable-column";
3
- import NumberColumn from "./number-column";
4
- import {ColumnModifier, ColumnName} from "../helpers/internal-types";
5
-
6
-
7
- export default class DateColumn<Table extends QueryTable<any, any>> extends ComparableColumn<Table, Date> {
8
-
9
- protected _type = 'date';
10
-
11
- constructor(table: Table, name: ColumnName, modifiers: ColumnModifier[] = []) {
12
- super(table, name, modifiers);
13
- }
14
-
15
- count(): NumberColumn<Table> {
16
- return new NumberColumn(this._table, this._name, this._modifiers.concat({ name: 'count' }));
17
- }
18
-
19
- }
@@ -1,25 +0,0 @@
1
- import QueryTable from "../query-table";
2
- import ComparableColumn from "./comparable-column";
3
- import {ColumnModifier, ColumnName} from "../helpers/internal-types";
4
-
5
-
6
- export default class NumberColumn<Table extends QueryTable<any, any>> extends ComparableColumn<Table, number> {
7
-
8
- protected _type = 'number';
9
-
10
- constructor(table: Table, name: ColumnName, modifiers: ColumnModifier[] = []) {
11
- super(table, name, modifiers);
12
- }
13
-
14
- count(): NumberColumn<Table> {
15
- return new NumberColumn(this._table, this._name, this._modifiers.concat({ name: 'count' }));
16
- }
17
-
18
- sum(): NumberColumn<Table> {
19
- return new NumberColumn<Table>(this._table, this._name, this._modifiers.concat({ name: 'sum' }));
20
- }
21
-
22
- avg(): NumberColumn<Table> {
23
- return new NumberColumn<Table>(this._table, this._name, this._modifiers.concat({ name: 'avg' }));
24
- }
25
- }
@@ -1,34 +0,0 @@
1
- import QueryTable from "../query-table";
2
- import NumberColumn from "./number-column";
3
- import GenericsHelper from "../helpers/generics-helper";
4
- import QueryColumnCondition from "../condition/query-column-condition";
5
- import {ColumnModifier, ColumnName} from "../helpers/internal-types";
6
-
7
-
8
- abstract class QueryColumn<Table extends QueryTable<any, any>, T> {
9
-
10
- protected _$type: GenericsHelper<T>;
11
- protected _type: string;
12
-
13
- constructor(
14
- protected _table: Table,
15
- protected _name: ColumnName,
16
- protected _modifiers: ColumnModifier[] = []
17
- ) {}
18
-
19
- abstract count(): NumberColumn<Table>; // TODO I had to copy-paste the implementation to every child class to avoid a circular dependency
20
-
21
- as(alias: string): this {
22
- return new (<any>this.constructor)(this._table, this._name, this._modifiers.concat({ name: 'as', params: alias }));
23
- }
24
-
25
- isNull() {
26
- return new QueryColumnCondition<Table, T>(this, 'is-null');
27
- }
28
-
29
- isNotNull() {
30
- return new QueryColumnCondition<Table, T>(this, 'is-not-null');
31
- }
32
- }
33
-
34
- export default QueryColumn;
@@ -1,47 +0,0 @@
1
- import QueryTable from "../query-table";
2
- import ComparableColumn from "./comparable-column";
3
- import NumberColumn from "./number-column";
4
- import QueryColumnCondition from "../condition/query-column-condition";
5
- import {ColumnModifier, ColumnName} from "../helpers/internal-types";
6
-
7
-
8
- export default class StringColumn<Table extends QueryTable<any, any>> extends ComparableColumn<Table, string> {
9
-
10
- protected _type = 'string';
11
-
12
- constructor(table: Table, name: ColumnName, modifiers: ColumnModifier[] = []) {
13
- super(table, name, modifiers);
14
- }
15
-
16
- count(): NumberColumn<Table> {
17
- return new NumberColumn(this._table, this._name, this._modifiers.concat({ name: 'count' }));
18
- }
19
-
20
- lower(): this {
21
- return new (<any>this.constructor)(this._table, this._name, this._modifiers.concat({ name: 'lower' }));
22
- }
23
-
24
- upper(): this {
25
- return new (<any>this.constructor)(this._table, this._name, this._modifiers.concat({ name: 'upper' }));
26
- }
27
-
28
- contains(value: string) {
29
- return this.like('%' + value + '%');
30
- }
31
-
32
- startsWith(value: string) {
33
- return this.like(value + '%');
34
- }
35
-
36
- endsWith(value: string) {
37
- return this.like('%' + value);
38
- }
39
-
40
- like(value: string) {
41
- return new QueryColumnCondition<Table, string>(this, 'like', value);
42
- }
43
-
44
- notLike(value: string) {
45
- return new QueryColumnCondition<Table, string>(this, 'not-like', value);
46
- }
47
- }
@@ -1,39 +0,0 @@
1
- import QueryColumnCondition from "../condition/query-column-condition";
2
- import QueryOrdering from "../other/query-ordering";
3
- import QueryTable from "../query-table";
4
- import QueryColumn from "./query-column";
5
- import QueryCondition from "../condition/query-condition";
6
- import QueryJoinCondition from "../condition/query-join-condition";
7
- import {ColumnModifier, ColumnName} from "../helpers/internal-types";
8
-
9
-
10
- abstract class ValueColumn<Table extends QueryTable<any, any>, T> extends QueryColumn<Table, T> {
11
-
12
- constructor(table: Table, name: ColumnName, modifiers: ColumnModifier[] = []) {
13
- super(table, name, modifiers);
14
- }
15
-
16
- asc() {
17
- return new QueryOrdering<Table>(this, 'ASC');
18
- }
19
-
20
- desc() {
21
- return new QueryOrdering<Table>(this, 'DESC');
22
- }
23
-
24
- eq<Table2 extends QueryTable<any, any>>(value: QueryColumn<Table2, T>): QueryJoinCondition<Table, Table2, T>;
25
- eq(value: T): QueryColumnCondition<Table, T>;
26
- eq<Table2 extends QueryTable<any, any>>(value: any): QueryCondition<any> {
27
- if (value instanceof QueryColumn) {
28
- return new QueryJoinCondition<Table, Table2, T>(this, 'eq', value);
29
- } else {
30
- return new QueryColumnCondition<Table, T>(this, 'eq', value);
31
- }
32
- }
33
-
34
- ne(value: T) {
35
- return new QueryColumnCondition<Table, T>(this, 'ne', value);
36
- }
37
- }
38
-
39
- export default ValueColumn;
@@ -1,28 +0,0 @@
1
- import QueryColumn from "../column/query-column";
2
- import QueryTable from "../query-table";
3
- import QueryCondition from "./query-condition";
4
- import QueryConditionChain from "./query-condition-chain";
5
- import {ConditionType} from "../helpers/internal-types";
6
-
7
-
8
- export default class QueryColumnCondition<Table extends QueryTable<any, any>, T> extends QueryCondition<Table> {
9
-
10
- protected _column: QueryColumn<Table, T>;
11
- protected _type: ConditionType;
12
- protected _values: T[];
13
-
14
- constructor(column: QueryColumn<Table, T>, type: ConditionType, ...values: T[]) {
15
- super();
16
- this._column = column;
17
- this._type = type;
18
- this._values = values;
19
- }
20
-
21
- and<Table2 extends QueryTable<any, any>>(condition: QueryCondition<Table2>): QueryConditionChain<Table | Table2> {
22
- return new QueryConditionChain<Table | Table2>(this, condition, 'and');
23
- }
24
-
25
- or<Table2 extends QueryTable<any, any>>(condition: QueryCondition<Table2>): QueryConditionChain<Table | Table2> {
26
- return new QueryConditionChain<Table | Table2>(this, condition, 'or');
27
- }
28
- }
@@ -1,42 +0,0 @@
1
- import QueryTable from "../query-table";
2
- import QueryCondition from "./query-condition";
3
- import GenericsHelper from "../helpers/generics-helper";
4
- import {ConditionChainType} from "../helpers/internal-types";
5
-
6
-
7
- export default class QueryConditionChain<Table extends QueryTable<any, any>> extends QueryCondition<Table> {
8
-
9
- protected _$type: GenericsHelper<Table>;
10
-
11
- protected _sibling: QueryCondition<any>;
12
- protected _child: QueryCondition<any>;
13
- protected _chainType: ConditionChainType;
14
- protected _parenthesis = false;
15
- protected _negation = false;
16
-
17
- constructor(sibling: QueryCondition<any>, child: QueryCondition<any>, chainType: ConditionChainType) {
18
- super();
19
- this._sibling = sibling;
20
- this._child = child;
21
- this._chainType = chainType;
22
- }
23
-
24
- // TODO how to call this
25
- $() {
26
- this._parenthesis = true;
27
- return this;
28
- }
29
-
30
- not() {
31
- this._negation = true;
32
- return this;
33
- }
34
-
35
- and<Table2 extends QueryTable<any, any>>(condition: QueryCondition<Table2>): QueryConditionChain<Table | Table2> {
36
- return new QueryConditionChain<Table | Table2>(this, condition, 'and');
37
- }
38
-
39
- or<Table2 extends QueryTable<any, any>>(condition: QueryCondition<Table2>): QueryConditionChain<Table | Table2> {
40
- return new QueryConditionChain<Table | Table2>(this, condition, 'or');
41
- }
42
- }
@@ -1,13 +0,0 @@
1
- import QueryTable from "../query-table";
2
- import QueryConditionChain from "./query-condition-chain";
3
-
4
- // TODO I had to copy-paste the method implementations to every child class to avoid circular dependencies
5
-
6
- abstract class QueryCondition<Table extends QueryTable<any, any>> {
7
-
8
- abstract and<Table2 extends QueryTable<any, any>>(condition: QueryCondition<Table2>): QueryConditionChain<Table | Table2>;
9
-
10
- abstract or<Table2 extends QueryTable<any, any>>(condition: QueryCondition<Table2>): QueryConditionChain<Table | Table2>;
11
- }
12
-
13
- export default QueryCondition;
@@ -1,27 +0,0 @@
1
- import QueryColumn from "../column/query-column";
2
- import QueryTable from "../query-table";
3
- import QueryCondition from "./query-condition";
4
- import QueryConditionChain from "./query-condition-chain";
5
-
6
-
7
- export default class QueryJoinCondition<Table1 extends QueryTable<any, any>, Table2 extends QueryTable<any, any>, T> extends QueryCondition<Table1 | Table2> {
8
-
9
- protected _column: QueryColumn<Table1, T>;
10
- protected _type: string;
11
- protected _otherColumn: QueryColumn<Table2, T>;
12
-
13
- constructor(column: QueryColumn<Table1, T>, type: string, otherColumn: QueryColumn<Table2, T>) {
14
- super();
15
- this._column = column;
16
- this._type = type;
17
- this._otherColumn = otherColumn;
18
- }
19
-
20
- and<Table3 extends QueryTable<any, any>>(condition: QueryCondition<Table3>): QueryConditionChain<Table1 | Table2 | Table3> {
21
- return new QueryConditionChain<Table1 | Table2 | Table3>(this, condition, 'and');
22
- }
23
-
24
- or<Table3 extends QueryTable<any, any>>(condition: QueryCondition<Table3>): QueryConditionChain<Table1 | Table2 | Table3> {
25
- return new QueryConditionChain<Table1 | Table2 | Table3>(this, condition, 'or');
26
- }
27
- }
@@ -1,31 +0,0 @@
1
- // query:
2
-
3
- export type QueryAction = 'select' | 'insert' | 'update' | 'delete';
4
-
5
- // columns:
6
-
7
- export type ColumnModifierType = 'as' | 'count' | 'min' | 'min' | 'max' | 'sum' | 'avg' | 'lower' | 'upper';
8
-
9
- export interface ColumnModifier {
10
- name: ColumnModifierType,
11
- params?: any
12
- }
13
-
14
- export type ColumnName = string | { name: string, alias: string };
15
-
16
- export type ColumnType = 'boolean' | 'number' | 'string' | 'date'; // FIXME use this in the columns, but it causes type errors
17
-
18
- // conditions:
19
-
20
- export type ConditionChainType = 'or' | 'and';
21
-
22
- export type ConditionType = 'eq' | 'ne' | 'lt' | 'lte' | 'gt' | 'gte' | 'in' | 'not-in' | 'between' | 'not-between'
23
- | 'like' | 'not-like' | 'is-null' | 'is-not-null';
24
-
25
- // joins:
26
-
27
- export type JoinType = 'inner' | 'left' | 'right' | 'full';
28
-
29
- // processor:
30
-
31
- export type QueryProcessor = (query: any) => Promise<any>;
@@ -1,17 +0,0 @@
1
- import QueryTable from "../query-table";
2
- import QueryJoinCondition from "../condition/query-join-condition";
3
- import JoinedTables from "./joined-tables";
4
- import {JoinType} from "../helpers/internal-types";
5
-
6
- export default class JoinedTablesChain<Tables extends QueryTable<any, any>> {
7
-
8
- constructor(
9
- protected _table: QueryTable<any, any>,
10
- protected _modifier: JoinType,
11
- protected _parent: JoinedTables<Tables> | QueryTable<any, any>
12
- ) {}
13
-
14
- on(condition: QueryJoinCondition<Tables, Tables, any>): JoinedTables<Tables> {
15
- return new JoinedTables(condition, this);
16
- }
17
- }
@@ -1,28 +0,0 @@
1
- import QueryTable from "../query-table";
2
- import JoinedTablesChain from "./joined-tables-chain";
3
- import QueryJoinCondition from "../condition/query-join-condition";
4
-
5
-
6
- export default class JoinedTables<Tables extends QueryTable<any, any>> {
7
-
8
- constructor(
9
- protected _condition: QueryJoinCondition<Tables, Tables, any>,
10
- protected _parent: JoinedTablesChain<Tables>
11
- ) {}
12
-
13
- innerJoin<JoinTable extends QueryTable<any, any>>(table: JoinTable): JoinedTablesChain<Tables | JoinTable> {
14
- return new JoinedTablesChain(table, 'inner', this);
15
- }
16
-
17
- leftJoin<JoinTable extends QueryTable<any, any>>(table: JoinTable): JoinedTablesChain<Tables | JoinTable> {
18
- return new JoinedTablesChain(table, 'left', this);
19
- }
20
-
21
- rightJoin<JoinTable extends QueryTable<any, any>>(table: JoinTable): JoinedTablesChain<Tables | JoinTable> {
22
- return new JoinedTablesChain(table, 'right', this);
23
- }
24
-
25
- fullJoin<JoinTable extends QueryTable<any, any>>(table: JoinTable): JoinedTablesChain<Tables | JoinTable> {
26
- return new JoinedTablesChain(table, 'full', this);
27
- }
28
- }
@@ -1,26 +0,0 @@
1
- import QueryColumn from "../column/query-column";
2
- import QueryTable from "../query-table";
3
-
4
-
5
- export default class QueryOrdering<Table extends QueryTable<any, any>> {
6
-
7
- protected _column: QueryColumn<Table, any>;
8
- protected _direction: 'ASC' | 'DESC';
9
- protected _nullsPosition: 'FIRST' | 'LAST';
10
-
11
- constructor(column: QueryColumn<Table, any>, direction: 'ASC' | 'DESC') {
12
- this._column = column;
13
- this._direction = direction;
14
- }
15
-
16
- nullsFirst(): this {
17
- this._nullsPosition = 'FIRST';
18
- return this;
19
- }
20
-
21
- nullsLast(): this {
22
- this._nullsPosition = 'LAST';
23
- return this;
24
- }
25
-
26
- }
@@ -1,68 +0,0 @@
1
- import QueryCondition from "../condition/query-condition";
2
- import QueryOrdering from "../other/query-ordering";
3
- import QueryTable from "../query-table";
4
- import QueryColumn from "../column/query-column";
5
- import { QueryProcessor, QueryAction } from "../helpers/internal-types";
6
-
7
-
8
- export default class SelectQuery<Entity, Table extends QueryTable<Entity, any>> {
9
-
10
- constructor(
11
- protected _queryProcessor: QueryProcessor,
12
- protected _tables: Table[]
13
- ) {}
14
-
15
- protected _distinct = false;
16
- protected _offset: number;
17
- protected _limit: number;
18
- protected _conditions: QueryCondition<Table>[] = [];
19
- protected _groupBy: QueryColumn<Table, any>[] = [];
20
- protected _having: QueryCondition<Table>[] = [];
21
- protected _orderings: (QueryColumn<Table, any> | QueryOrdering<Table>)[] = [];
22
- protected _columns: QueryColumn<Table, any>[] = [];
23
- protected _action: QueryAction;
24
-
25
- offset(offset: number): this {
26
- this._offset = offset;
27
- return this;
28
- }
29
-
30
- limit(limit: number): this {
31
- this._limit = limit;
32
- return this;
33
- }
34
-
35
- distinct(): this {
36
- this._distinct = true;
37
- return this;
38
- }
39
-
40
- where(...conditions: QueryCondition<Table>[]): this {
41
- this._conditions = conditions;
42
- return this;
43
- }
44
-
45
- groupBy(...columns: QueryColumn<Table, any>[]): this {
46
- this._groupBy = columns;
47
- return this;
48
- }
49
-
50
- having(...conditions: QueryCondition<Table>[]): this {
51
- this._having = conditions;
52
- return this;
53
- }
54
-
55
- orderBy(...orderings: (QueryColumn<Table, any> | QueryOrdering<Table>)[]): this {
56
- this._orderings = orderings;
57
- return this;
58
- }
59
-
60
- select(): Promise<Entity[]>
61
- select<T>(column: QueryColumn<Table, T>): Promise<T[]>
62
- select(...columns: QueryColumn<Table, any>[]): Promise<any[]>
63
- select(...columns: QueryColumn<Table, any>[]): Promise<any[]> {
64
- this._columns = columns;
65
- this._action = 'select';
66
- return this._queryProcessor(this);
67
- }
68
- }
@@ -1,35 +0,0 @@
1
- import QueryTable from "../query-table";
2
- import QueryCondition from "../condition/query-condition";
3
- import QueryColumn from "../column/query-column";
4
- import { QueryProcessor, QueryAction } from "../helpers/internal-types";
5
-
6
-
7
- export default class TableConditionQuery<Entity, Table extends QueryTable<Entity, any>> {
8
-
9
- constructor(
10
- protected _queryProcessor: QueryProcessor,
11
- protected _table: Table,
12
- protected _conditions: QueryCondition<Table>[]
13
- ) {}
14
-
15
- protected _columns: QueryColumn<Table, any>[] = [];
16
- protected _action: QueryAction;
17
- protected _entity: Entity | Partial<Entity>;
18
-
19
- update(entity: Partial<Entity>): Promise<number> {
20
- this._entity = entity;
21
- this._action = 'update';
22
- return this._queryProcessor(this);
23
- }
24
-
25
- delete(): Promise<number> {
26
- this._action = 'delete';
27
- return this._queryProcessor(this);
28
- }
29
-
30
- count(): Promise<number> {
31
- this._columns = [this._table.$all.count()];
32
- this._action = 'select';
33
- return this._queryProcessor(this).then((rows: number[]) => rows[0]);
34
- }
35
- }
@@ -1,72 +0,0 @@
1
- import QueryTable from "../query-table";
2
- import TableConditionQuery from "./table-condition-query";
3
- import QueryCondition from "../condition/query-condition";
4
- import ValueColumn from "../column/value-column";
5
- import QueryColumn from "../column/query-column";
6
- import { QueryProcessor, QueryAction } from "../helpers/internal-types";
7
-
8
-
9
- export default class TableQuery<Entity, Id, Table extends QueryTable<Entity, Id>> {
10
-
11
- constructor(
12
- protected _queryProcessor: QueryProcessor,
13
- protected _table: Table
14
- ) {}
15
-
16
- protected _entity: Entity | Entity[] | Partial<Entity>;
17
- protected _action: QueryAction;
18
- protected _columns: QueryColumn<Table, any>[] = [];
19
-
20
- where(...conditions: QueryCondition<Table>[]) {
21
- return new TableConditionQuery<Entity, Table>(this._queryProcessor, this._table, conditions);
22
- }
23
-
24
- insert(entity: Entity): Promise<any> // returns the generated ID, but not other kinds of IDs, so the type is unknown (mysql limitations)
25
- insert(entities: Entity[]): Promise<void>
26
- insert(param: any): Promise<any> {
27
- this._entity = param;
28
- this._action = 'insert';
29
- return this._queryProcessor(this);
30
- }
31
-
32
- deleteAll(): Promise<number> {
33
- this._action = 'delete';
34
- return this._queryProcessor(this);
35
- }
36
-
37
- updateAll(entity: Partial<Entity>): Promise<number> {
38
- this._entity = entity;
39
- this._action = 'update';
40
- return this._queryProcessor(this);
41
- }
42
-
43
- countAll(): Promise<number> {
44
- this._columns = [this._table.$all.count()];
45
- this._action = 'select';
46
- return this._queryProcessor(this).then((rows: any[]) => rows[0]);
47
- }
48
-
49
- delete(id: Id): Promise<boolean> {
50
- return this._whereId(id).delete().then(count => count > 0);
51
- }
52
-
53
- update(id: Id, entity: Partial<Entity>): Promise<boolean> {
54
- return this._whereId(id).update(entity).then(count => count > 0);
55
- }
56
-
57
- get(id: Id): Promise<Entity | undefined> {
58
- let query = this._whereId(id);
59
- return this._queryProcessor({ _action: 'select', ...query })
60
- .then((rows: Entity[]) => rows[0]);
61
- }
62
-
63
- _whereId(id: Id): TableConditionQuery<Entity, Table> {
64
- // TODO remove assertions if $id typing is fixed
65
- let $id = (this._table as any).$id;
66
- if ($id instanceof ValueColumn) {
67
- return this.where($id.eq(id));
68
- } else {
69
- return this.where(...Object.keys($id).map(key => ((this._table as any)[key] as ValueColumn<Table, any>).eq((id as any)[key] as any)));
70
- }
71
- }
72
- }
@@ -1,25 +0,0 @@
1
- import QueryTable from './query-table';
2
- import SelectQuery from './query/select-query';
3
- import { QueryProcessor } from "./helpers/internal-types";
4
- import JoinedTables from "./join/joined-tables";
5
- import TableQuery from "./query/table-query";
6
-
7
-
8
- export default class QuerySource {
9
-
10
- constructor(protected _queryProcessor: QueryProcessor) {}
11
-
12
- from<Entity, Table1 extends QueryTable<Entity, any>>(table1: Table1 & QueryTable<Entity, any>): SelectQuery<Entity, Table1>
13
- from<Tables extends QueryTable<any, any>>(tables: JoinedTables<Tables>): SelectQuery<any, Tables>
14
- from<Table1 extends QueryTable<any, any>, Table2 extends QueryTable<any, any>>(table1: Table1, table2: Table2): SelectQuery<any, Table1 | Table2>
15
- from<Table1 extends QueryTable<any, any>, Table2 extends QueryTable<any, any>, Table3 extends QueryTable<any, any>>(table1: Table1, table2: Table2, table3: Table3): SelectQuery<any, Table1 | Table2 | Table3>
16
- from<Entity, Table1 extends QueryTable<any, any>, Table2 extends QueryTable<any, any>, Table3 extends QueryTable<any, any>>(table1: any, table2?: any, table3?: any) {
17
- if (table3 != null) return new SelectQuery<any, Table1 | Table2 | Table3>(this._queryProcessor, [table1, table2, table3]);
18
- else if (table2 != null) return new SelectQuery<any, Table1 | Table2>(this._queryProcessor, [table1, table2]);
19
- return new SelectQuery<Entity, Table1>(this._queryProcessor, [table1]);
20
- }
21
-
22
- table<Entity, Id, Table extends QueryTable<Entity, Id>>(table: Table & QueryTable<Entity, Id>): TableQuery<Entity, Id, Table> {
23
- return new TableQuery<Entity, Id, Table>(this._queryProcessor, table);
24
- }
25
- }