taon-type-sql 21.0.23 → 21.0.25

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 (53) 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_.js +26 -14
  7. package/lib-prod/builder/column/basic-column.js +8 -10
  8. package/lib-prod/builder/column/boolean-column.js +8 -11
  9. package/lib-prod/builder/column/comparable-column.js +35 -38
  10. package/lib-prod/builder/column/date-column.js +8 -11
  11. package/lib-prod/builder/column/number-column.js +14 -17
  12. package/lib-prod/builder/column/query-column.js +15 -21
  13. package/lib-prod/builder/column/string-column.js +29 -32
  14. package/lib-prod/builder/column/value-column.js +20 -22
  15. package/lib-prod/builder/condition/query-column-condition.js +13 -19
  16. package/lib-prod/builder/condition/query-condition-chain.js +24 -31
  17. package/lib-prod/builder/condition/query-condition.js +2 -4
  18. package/lib-prod/builder/condition/query-join-condition.js +13 -19
  19. package/lib-prod/builder/helpers/generics-helper.js +2 -4
  20. package/lib-prod/builder/helpers/internal-types.js +1 -0
  21. package/lib-prod/builder/join/joined-tables-chain.js +9 -12
  22. package/lib-prod/builder/join/joined-tables.js +17 -20
  23. package/lib-prod/builder/other/query-ordering.js +13 -19
  24. package/lib-prod/builder/query/select-query.js +44 -50
  25. package/lib-prod/builder/query/table-condition-query.js +21 -26
  26. package/lib-prod/builder/query/table-query.js +49 -51
  27. package/lib-prod/builder/query-source.js +15 -16
  28. package/lib-prod/builder/query-table.js +18 -23
  29. package/lib-prod/client/mysql.js +4 -7
  30. package/lib-prod/client/pg.js +4 -7
  31. package/lib-prod/client/query-processor.js +64 -39
  32. package/lib-prod/converter/param-converter.js +24 -21
  33. package/lib-prod/converter/parameterized-converter.js +10 -13
  34. package/lib-prod/converter/query-converter.js +256 -244
  35. package/lib-prod/converter/result-converter.js +70 -62
  36. package/lib-prod/converter/sql-converter.js +3 -6
  37. package/lib-prod/converter/type-converter.js +32 -28
  38. package/lib-prod/converter/types.js +1 -0
  39. package/lib-prod/env/env.angular-node-app.js +66 -130
  40. package/lib-prod/env/env.docs-webapp.js +66 -130
  41. package/lib-prod/env/env.electron-app.js +66 -130
  42. package/lib-prod/env/env.mobile-app.js +66 -130
  43. package/lib-prod/env/env.npm-lib-and-cli-tool.js +66 -130
  44. package/lib-prod/env/env.vscode-plugin.js +66 -130
  45. package/lib-prod/env/index.js +6 -6
  46. package/lib-prod/index._auto-generated_.js +5 -0
  47. package/lib-prod/index.js +25 -46
  48. package/lib-prod/migrations/index.js +2 -1
  49. package/lib-prod/migrations/migrations_index._auto-generated_.js +3 -0
  50. package/lib-prod/package.json +1 -1
  51. package/package.json +1 -1
  52. package/websql/package.json +1 -1
  53. package/websql-prod/package.json +1 -1
@@ -1,20 +1,14 @@
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
- }
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
+ }
17
14
  }
18
- export {
19
- QueryOrdering as default
20
- };
@@ -1,51 +1,45 @@
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
- }
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
+ }
48
45
  }
49
- export {
50
- SelectQuery as default
51
- };
@@ -1,27 +1,22 @@
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
- }
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
+ }
24
22
  }
25
- export {
26
- TableConditionQuery as default
27
- };
@@ -1,54 +1,52 @@
1
1
  import TableConditionQuery from "./table-condition-query";
2
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
- }
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
+ }
51
52
  }
52
- export {
53
- TableQuery as default
54
- };
@@ -1,18 +1,17 @@
1
- import SelectQuery from "./query/select-query";
1
+ import SelectQuery from './query/select-query';
2
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
- }
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
+ }
15
17
  }
16
- export {
17
- QuerySource as default
18
- };
@@ -1,27 +1,22 @@
1
1
  import BasicColumn from "./column/basic-column";
2
2
  import JoinedTablesChain from "./join/joined-tables-chain";
3
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
- }
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
+ }
23
21
  }
24
- var query_table_default = QueryTable;
25
- export {
26
- query_table_default as default
27
- };
22
+ export default QueryTable;
@@ -1,10 +1,7 @@
1
1
  import QuerySource from "../builder/query-source";
2
2
  import { createQueryProcessor } from "./query-processor";
3
- class MySqlQuerySource extends QuerySource {
4
- constructor(client, options = {}) {
5
- super(createQueryProcessor(client, options, "mysql"));
6
- }
3
+ export default class MySqlQuerySource extends QuerySource {
4
+ constructor(client, options = {}) {
5
+ super(createQueryProcessor(client, options, 'mysql'));
6
+ }
7
7
  }
8
- export {
9
- MySqlQuerySource as default
10
- };
@@ -1,10 +1,7 @@
1
1
  import QuerySource from "../builder/query-source";
2
2
  import { createQueryProcessor } from "./query-processor";
3
- class PgQuerySource extends QuerySource {
4
- constructor(client, options = {}) {
5
- super(createQueryProcessor(client, options, "pg"));
6
- }
3
+ export default class PgQuerySource extends QuerySource {
4
+ constructor(client, options = {}) {
5
+ super(createQueryProcessor(client, options, 'pg'));
6
+ }
7
7
  }
8
- export {
9
- PgQuerySource as default
10
- };
@@ -1,44 +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(
5
- "query processor"
6
- // Level.__NOTHING
7
- );
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');
8
5
  const DEFAULT_OPTIONS = {
9
- lineBreaks: false,
10
- parameterized: true,
11
- logging: true,
12
- identifierQuote: '"'
6
+ lineBreaks: false,
7
+ parameterized: true,
8
+ logging: true,
9
+ identifierQuote: '"'
13
10
  };
14
11
  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);
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);
39
23
  }
40
- };
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
+ };
41
69
  }
42
- export {
43
- createQueryProcessor
44
- };
@@ -1,23 +1,26 @@
1
- function convertSubstitutionParam(param) {
2
- if (param == null) return "NULL";
3
- if (typeof param === "string" || param instanceof String) {
4
- return `'${String(param)}'`;
5
- } else if (typeof param === "boolean" || param instanceof Boolean) {
6
- return String(param).toUpperCase();
7
- } else if (param instanceof Date) {
8
- return `'${param.toISOString()}'`;
9
- } else if (typeof param === "number" || param instanceof Number) {
10
- return String(param);
11
- }
12
- return `'${JSON.stringify(param)}'`;
1
+ export function convertSubstitutionParam(param) {
2
+ if (param == null)
3
+ return 'NULL';
4
+ if (typeof param === 'string' || param instanceof String) {
5
+ return `'${String(param)}'`;
6
+ }
7
+ else if (typeof param === 'boolean' || param instanceof Boolean) {
8
+ return String(param).toUpperCase();
9
+ }
10
+ else if (param instanceof Date) {
11
+ return `'${param.toISOString()}'`;
12
+ }
13
+ else if (typeof param === 'number' || param instanceof Number) {
14
+ return String(param);
15
+ }
16
+ return `'${JSON.stringify(param)}'`;
13
17
  }
14
- function convertEscapedParam(param) {
15
- if (typeof param === "object" && !(param == null || param instanceof String || param instanceof Number || param instanceof Boolean || param instanceof Date)) {
16
- return JSON.stringify(param);
17
- }
18
- return param;
18
+ // node mysql doesn't have an typeCast equivalent solution for the other direction
19
+ // node-postgres: https://github.com/brianc/node-postgres/issues/442
20
+ export function convertEscapedParam(param) {
21
+ if (typeof param === 'object' && !(param == null || param instanceof String || param instanceof Number ||
22
+ param instanceof Boolean || param instanceof Date)) {
23
+ return JSON.stringify(param);
24
+ }
25
+ return param;
19
26
  }
20
- export {
21
- convertEscapedParam,
22
- convertSubstitutionParam
23
- };
@@ -1,17 +1,14 @@
1
1
  import { createQueryConverter } from "./query-converter";
2
- import { convertEscapedParam } from "./param-converter";
3
- let pgParamConverter = (index) => "$" + index;
4
- let mySqlParamConverter = (index) => "?";
2
+ import { convertEscapedParam } from './param-converter';
3
+ let pgParamConverter = (index) => '$' + index;
4
+ let mySqlParamConverter = (index) => '?';
5
5
  function convertSingleParam(param, params, paramConverter) {
6
- params.push(convertEscapedParam(param));
7
- return paramConverter(params.length);
6
+ params.push(convertEscapedParam(param));
7
+ return paramConverter(params.length);
8
8
  }
9
- function convertQueryToParameterizedSQL(query, options, engine) {
10
- let params = [];
11
- let paramConverter = engine === "mysql" ? mySqlParamConverter : pgParamConverter;
12
- let sql = createQueryConverter((param) => convertSingleParam(param, params, paramConverter), options, engine)(query);
13
- return { sql, params };
9
+ export function convertQueryToParameterizedSQL(query, options, engine) {
10
+ let params = [];
11
+ let paramConverter = engine === 'mysql' ? mySqlParamConverter : pgParamConverter;
12
+ let sql = createQueryConverter((param) => convertSingleParam(param, params, paramConverter), options, engine)(query);
13
+ return { sql, params };
14
14
  }
15
- export {
16
- convertQueryToParameterizedSQL
17
- };