@sqb/builder 4.11.2 → 4.12.0

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 (66) hide show
  1. package/README.md +9 -24
  2. package/cjs/helpers.js +1 -1
  3. package/cjs/op.initializers.js +1 -1
  4. package/cjs/query/delete-query.js +2 -3
  5. package/cjs/query/insert-query.js +3 -5
  6. package/cjs/query/query.js +1 -1
  7. package/cjs/query/returning-query.js +4 -3
  8. package/cjs/query/select-query.js +4 -8
  9. package/cjs/query/union-query.js +1 -1
  10. package/cjs/query/update-query.js +3 -4
  11. package/cjs/serialize-context.js +60 -18
  12. package/cjs/sql-objects/case-statement.js +3 -4
  13. package/cjs/sql-objects/coalesce-statement.js +1 -2
  14. package/cjs/sql-objects/count-statement.js +3 -1
  15. package/cjs/sql-objects/field-expression.js +4 -5
  16. package/cjs/sql-objects/group-column.js +3 -3
  17. package/cjs/sql-objects/join-statement.js +4 -6
  18. package/cjs/sql-objects/lower-statement.js +1 -2
  19. package/cjs/sql-objects/max-statement.js +1 -2
  20. package/cjs/sql-objects/min-statement.js +1 -2
  21. package/cjs/sql-objects/operators/comp-operator.js +4 -6
  22. package/cjs/sql-objects/operators/logical-operator.js +1 -1
  23. package/cjs/sql-objects/operators/op-between.js +3 -7
  24. package/cjs/sql-objects/operators/op-exists.js +1 -1
  25. package/cjs/sql-objects/order-column.js +4 -4
  26. package/cjs/sql-objects/param-expression.js +1 -2
  27. package/cjs/sql-objects/returning-column.js +2 -3
  28. package/cjs/sql-objects/sequence-getter-statement.js +2 -3
  29. package/cjs/sql-objects/string-agg-statement.js +9 -5
  30. package/cjs/sql-objects/table-name.js +2 -3
  31. package/cjs/sql-objects/upper-statement.js +1 -2
  32. package/cjs/sqlobject.initializers.js +1 -1
  33. package/esm/helpers.js +1 -1
  34. package/esm/op.initializers.js +2 -2
  35. package/esm/query/delete-query.js +2 -3
  36. package/esm/query/insert-query.js +3 -5
  37. package/esm/query/query.js +1 -1
  38. package/esm/query/returning-query.js +4 -3
  39. package/esm/query/select-query.js +4 -8
  40. package/esm/query/union-query.js +1 -1
  41. package/esm/query/update-query.js +3 -4
  42. package/esm/serialize-context.js +60 -18
  43. package/esm/sql-objects/case-statement.js +3 -4
  44. package/esm/sql-objects/coalesce-statement.js +1 -2
  45. package/esm/sql-objects/count-statement.js +3 -1
  46. package/esm/sql-objects/field-expression.js +4 -5
  47. package/esm/sql-objects/group-column.js +3 -3
  48. package/esm/sql-objects/join-statement.js +4 -6
  49. package/esm/sql-objects/lower-statement.js +1 -2
  50. package/esm/sql-objects/max-statement.js +1 -2
  51. package/esm/sql-objects/min-statement.js +1 -2
  52. package/esm/sql-objects/operators/comp-operator.js +4 -6
  53. package/esm/sql-objects/operators/logical-operator.js +1 -1
  54. package/esm/sql-objects/operators/op-between.js +3 -7
  55. package/esm/sql-objects/operators/op-exists.js +1 -1
  56. package/esm/sql-objects/order-column.js +4 -4
  57. package/esm/sql-objects/param-expression.js +1 -2
  58. package/esm/sql-objects/returning-column.js +2 -3
  59. package/esm/sql-objects/sequence-getter-statement.js +2 -3
  60. package/esm/sql-objects/string-agg-statement.js +9 -5
  61. package/esm/sql-objects/table-name.js +2 -3
  62. package/esm/sql-objects/upper-statement.js +1 -2
  63. package/esm/sqlobject.initializers.js +1 -1
  64. package/package.json +4 -3
  65. package/types/op.initializers.d.ts +1 -1
  66. package/types/query/select-query.d.ts +1 -1
@@ -50,7 +50,7 @@ class StringAGGStatement extends serializable_js_1.Serializable {
50
50
  field: ctx.anyToSQL(this._field),
51
51
  delimiter: this._delimiter,
52
52
  orderBy: this.__serializeOrderColumns(ctx),
53
- alias: this._alias
53
+ alias: this._alias,
54
54
  };
55
55
  return ctx.serialize(this._type, q, () => this.__defaultSerialize(ctx, q));
56
56
  }
@@ -69,10 +69,14 @@ class StringAGGStatement extends serializable_js_1.Serializable {
69
69
  });
70
70
  }
71
71
  __defaultSerialize(ctx, o) {
72
- return 'string_agg(' + o.field +
73
- ',\'' + o.delimiter + '\'' +
74
- (o.orderBy ? ' ' + o.orderBy : '') + ')' +
75
- (o.alias ? ' ' + o.alias : '');
72
+ return ('string_agg(' +
73
+ o.field +
74
+ ",'" +
75
+ o.delimiter +
76
+ "'" +
77
+ (o.orderBy ? ' ' + o.orderBy : '') +
78
+ ')' +
79
+ (o.alias ? ' ' + o.alias : ''));
76
80
  }
77
81
  }
78
82
  exports.StringAGGStatement = StringAGGStatement;
@@ -23,9 +23,8 @@ class TableName extends serializable_js_1.Serializable {
23
23
  return ctx.serialize(this._type, {
24
24
  schema: this.schema,
25
25
  table: this.table,
26
- alias: this.alias
27
- }, () => (this.schema ? this.schema + '.' : '') + this.table +
28
- (this.alias ? ' ' + this.alias : ''));
26
+ alias: this.alias,
27
+ }, () => (this.schema ? this.schema + '.' : '') + this.table + (this.alias ? ' ' + this.alias : ''));
29
28
  }
30
29
  }
31
30
  exports.TableName = TableName;
@@ -32,8 +32,7 @@ class UpperStatement extends serializable_js_1.Serializable {
32
32
  return ctx.serialize(this._type, q, () => this.__defaultSerialize(ctx, q));
33
33
  }
34
34
  __defaultSerialize(ctx, o) {
35
- return 'upper(' + o + ')' +
36
- (this._alias ? ' ' + this._alias : '');
35
+ return 'upper(' + o + ')' + (this._alias ? ' ' + this._alias : '');
37
36
  }
38
37
  }
39
38
  exports.UpperStatement = UpperStatement;
@@ -130,7 +130,7 @@ function Param(arg0, arg1, arg2) {
130
130
  return new param_expression_js_1.ParamExpression({
131
131
  name: arg0,
132
132
  dataType: arg1,
133
- isArray: arg2
133
+ isArray: arg2,
134
134
  });
135
135
  }
136
136
  exports.Param = Param;
package/esm/helpers.js CHANGED
@@ -11,7 +11,7 @@ export function printArray(arr, sep, lfLen) {
11
11
  /* istanbul ignore next */
12
12
  if (s === undefined)
13
13
  continue;
14
- line += (k > 0 ? sep : '');
14
+ line += k > 0 ? sep : '';
15
15
  if (line.length > lfLen) {
16
16
  out += (out ? '\n' : '') + line;
17
17
  line = '';
@@ -124,8 +124,8 @@ const op = {
124
124
  '!is': IsNot,
125
125
  exists: Exists,
126
126
  notExists: NotExists,
127
- '!exists': NotExists
127
+ '!exists': NotExists,
128
128
  };
129
129
  Object.assign(WrapOps, op);
130
130
  export { op };
131
- export { And, Or, Eq, Eq as Equal, Ne, Ne as NotEqual, Gt, Gt as GreaterThan, Gte, Gte as GreaterAnEqualTo, Lt, Lt as LowerThan, Lte, Lte as LowerAndEqualTo, Between, NotBetween, In, NotIn, NotIn as Nin, Like, NotLike, NotLike as NLike, Ilike, NotILike, NotILike as Nilike, Is, IsNot, Exists, NotExists, Not };
131
+ export { And, Or, Eq, Eq as Equal, Ne, Ne as NotEqual, Gt, Gt as GreaterThan, Gte, Gte as GreaterAnEqualTo, Lt, Lt as LowerThan, Lte, Lte as LowerAndEqualTo, Between, NotBetween, In, NotIn, NotIn as Nin, Like, NotLike, NotLike as NLike, Ilike, NotILike, NotILike as Nilike, Is, IsNot, Exists, NotExists, Not, };
@@ -27,13 +27,12 @@ export class DeleteQuery extends Query {
27
27
  _serialize(ctx) {
28
28
  const o = {
29
29
  table: this._table._serialize(ctx),
30
- where: this._serializeWhere(ctx)
30
+ where: this._serializeWhere(ctx),
31
31
  };
32
32
  return ctx.serialize(this._type, o, () => this.__defaultSerialize(ctx, o));
33
33
  }
34
34
  __defaultSerialize(ctx, o) {
35
- return 'delete from ' + o.table +
36
- (o.where ? '\n' + o.where : '');
35
+ return 'delete from ' + o.table + (o.where ? '\n' + o.where : '');
37
36
  }
38
37
  /**
39
38
  *
@@ -8,8 +8,7 @@ export class InsertQuery extends ReturningQuery {
8
8
  super();
9
9
  if (!tableName || !(typeof tableName === 'string' || isRawStatement(tableName)))
10
10
  throw new TypeError('String or Raw instance required as first argument (tableName) for InsertQuery');
11
- if (!input || !((typeof input === 'object' && !Array.isArray(input)) ||
12
- input.isSelect))
11
+ if (!input || !((typeof input === 'object' && !Array.isArray(input)) || input.isSelect))
13
12
  throw new TypeError('Object or SelectQuery instance required as second argument (input) for InsertQuery');
14
13
  this._table = typeof tableName === 'string' ? new TableName(tableName) : tableName;
15
14
  this._input = input;
@@ -25,10 +24,9 @@ export class InsertQuery extends ReturningQuery {
25
24
  table: this._table._serialize(ctx),
26
25
  columns: this.__serializeColumns(ctx),
27
26
  values: this.__serializeValues(ctx),
28
- returning: this.__serializeReturning(ctx)
27
+ returning: this.__serializeReturning(ctx),
29
28
  };
30
- let out = 'insert into ' + o.table + '\n\t(' +
31
- o.columns + ')\n\bvalues\n\t(' + o.values + ')\b';
29
+ let out = 'insert into ' + o.table + '\n\t(' + o.columns + ')\n\bvalues\n\t(' + o.values + ')\b';
32
30
  if (o.returning)
33
31
  out += '\n' + o.returning;
34
32
  return out;
@@ -22,7 +22,7 @@ export class Query extends Serializable {
22
22
  sql: flattenText(sql, { noWrap: !ctx.prettyPrint }),
23
23
  params: ctx.preparedParams,
24
24
  paramOptions: ctx.paramOptions,
25
- returningFields: ctx.returningFields
25
+ returningFields: ctx.returningFields,
26
26
  };
27
27
  }
28
28
  values(obj) {
@@ -10,12 +10,13 @@ export class ReturningQuery extends Query {
10
10
  if (!columns)
11
11
  return this;
12
12
  // noinspection JSMismatchedCollectionQueryUpdate
13
- this._returningColumns = columns.length ?
14
- columns.reduce((a, v) => {
13
+ this._returningColumns = columns.length
14
+ ? columns.reduce((a, v) => {
15
15
  if (v)
16
16
  a.push(new ReturningColumn(v));
17
17
  return a;
18
- }, []) : undefined;
18
+ }, [])
19
+ : undefined;
19
20
  return this;
20
21
  }
21
22
  /**
@@ -139,7 +139,7 @@ export class SelectQuery extends Query {
139
139
  groupBy: this.__serializeGroupColumns(ctx),
140
140
  orderBy: this.__serializeOrderColumns(ctx),
141
141
  limit: this._limit,
142
- offset: this._offset
142
+ offset: this._offset,
143
143
  };
144
144
  return ctx.serialize(this._type, o, () => {
145
145
  let out = 'select';
@@ -148,15 +148,11 @@ export class SelectQuery extends Query {
148
148
  // columns part
149
149
  /* istanbul ignore else */
150
150
  if (o.columns) {
151
- out += (o.columns.indexOf('\n') >= 0) ?
152
- '\n\t' + o.columns + '\b' :
153
- ' ' + o.columns;
151
+ out += o.columns.indexOf('\n') >= 0 ? '\n\t' + o.columns + '\b' : ' ' + o.columns;
154
152
  }
155
153
  // from part
156
154
  if (o.from) {
157
- out += (o.columns.length > 60 ||
158
- o.columns.indexOf('\n') >= 0 ? '\n' : ' ') +
159
- o.from;
155
+ out += (o.columns.length > 60 || o.columns.indexOf('\n') >= 0 ? '\n' : ' ') + o.from;
160
156
  }
161
157
  // join part
162
158
  if (o.join)
@@ -215,7 +211,7 @@ export class SelectQuery extends Query {
215
211
  }
216
212
  return ctx.serialize(SerializationType.SELECT_QUERY_FROM, arr, () => {
217
213
  const s = arr.join(',');
218
- return s ? ('from' + (s.substring(0, 1) !== '\n' ? ' ' : '') + s) : '';
214
+ return s ? 'from' + (s.substring(0, 1) !== '\n' ? ' ' : '') + s : '';
219
215
  });
220
216
  }
221
217
  /**
@@ -16,7 +16,7 @@ export class UnionQuery extends Query {
16
16
  const queries = this._queries.map(q => q._serialize(ctx));
17
17
  const q = {
18
18
  queries,
19
- unionType: this._unionType
19
+ unionType: this._unionType,
20
20
  };
21
21
  return ctx.serialize(this._type, q, () => this.__defaultSerialize(ctx, q));
22
22
  }
@@ -9,8 +9,7 @@ export class UpdateQuery extends ReturningQuery {
9
9
  super();
10
10
  if (!tableName || !(typeof tableName === 'string' || isRawStatement(tableName)))
11
11
  throw new TypeError('String or Raw instance required as first argument (tableName) for UpdateQuery');
12
- if (!input || !((typeof input === 'object' && !Array.isArray(input)) ||
13
- input.isSelect))
12
+ if (!input || !((typeof input === 'object' && !Array.isArray(input)) || input.isSelect))
14
13
  throw new TypeError('Object or Raw instance required as second argument (input) for UpdateQuery');
15
14
  this._table = typeof tableName === 'string' ? new TableName(tableName) : tableName;
16
15
  this._input = input;
@@ -34,7 +33,7 @@ export class UpdateQuery extends ReturningQuery {
34
33
  table: this._table._serialize(ctx),
35
34
  values: this.__serializeValues(ctx),
36
35
  where: this.__serializeWhere(ctx),
37
- returning: this.__serializeReturning(ctx)
36
+ returning: this.__serializeReturning(ctx),
38
37
  };
39
38
  let out = 'update ' + o.table + ' set \n\t' + o.values + '\b';
40
39
  if (o.where)
@@ -53,7 +52,7 @@ export class UpdateQuery extends ReturningQuery {
53
52
  const value = ctx.anyToSQL(allValues[n]);
54
53
  arr.push({
55
54
  field: n,
56
- value
55
+ value,
57
56
  });
58
57
  }
59
58
  return ctx.serialize(SerializationType.UPDATE_QUERY_VALUES, arr, () => {
@@ -5,16 +5,62 @@ import { isLogicalOperator, isQuery, isSerializable } from './typeguards.js';
5
5
  export class SerializeContext {
6
6
  constructor(opts) {
7
7
  this.reservedWords = [
8
- 'schema', 'table', 'field', 'index', 'foreign', 'key',
9
- 'select', 'insert', 'update', 'delete', 'with', 'merge',
10
- 'join', 'inner', 'outer', 'left', 'right', 'full',
11
- 'from', 'where', 'order', 'by', 'group', 'having',
12
- 'acs', 'ascending', 'dsc', 'descending', 'distinct',
13
- 'and', 'or', 'not', 'between', 'null', 'like', 'ilike',
14
- 'count', 'sum', 'average', 'avg', 'cascade', 'authorization',
15
- 'create', 'add', 'drop', 'alter', 'index', 'private', 'sequence',
16
- 'default', 'constraint', 'references', 'primary', 'foreign',
17
- 'user', 'password'
8
+ 'schema',
9
+ 'table',
10
+ 'field',
11
+ 'index',
12
+ 'foreign',
13
+ 'key',
14
+ 'select',
15
+ 'insert',
16
+ 'update',
17
+ 'delete',
18
+ 'with',
19
+ 'merge',
20
+ 'join',
21
+ 'inner',
22
+ 'outer',
23
+ 'left',
24
+ 'right',
25
+ 'full',
26
+ 'from',
27
+ 'where',
28
+ 'order',
29
+ 'by',
30
+ 'group',
31
+ 'having',
32
+ 'acs',
33
+ 'ascending',
34
+ 'dsc',
35
+ 'descending',
36
+ 'distinct',
37
+ 'and',
38
+ 'or',
39
+ 'not',
40
+ 'between',
41
+ 'null',
42
+ 'like',
43
+ 'ilike',
44
+ 'count',
45
+ 'sum',
46
+ 'average',
47
+ 'avg',
48
+ 'cascade',
49
+ 'authorization',
50
+ 'create',
51
+ 'add',
52
+ 'drop',
53
+ 'alter',
54
+ 'index',
55
+ 'private',
56
+ 'sequence',
57
+ 'default',
58
+ 'constraint',
59
+ 'references',
60
+ 'primary',
61
+ 'foreign',
62
+ 'user',
63
+ 'password',
18
64
  ];
19
65
  if (opts)
20
66
  Object.assign(this, opts);
@@ -52,9 +98,7 @@ export class SerializeContext {
52
98
  if (typeof v === 'object') {
53
99
  if (isSerializable(v)) {
54
100
  const s = v._serialize(this);
55
- return s ? (isQuery(v) || isLogicalOperator(v) ? '(' + s + ')' : s) :
56
- /* istanbul ignore next */
57
- '';
101
+ return s ? (isQuery(v) || isLogicalOperator(v) ? '(' + s + ')' : s) : /* istanbul ignore next */ '';
58
102
  }
59
103
  if (v instanceof Date) {
60
104
  return this.serialize(SerializationType.DATE_VALUE, v, () => this.dateToSQL(v));
@@ -78,7 +122,7 @@ export class SerializeContext {
78
122
  *
79
123
  */
80
124
  stringToSQL(val) {
81
- return '\'' + String(val).replace(/'/g, '\'\'') + '\'';
125
+ return "'" + String(val).replace(/'/g, "''") + "'";
82
126
  }
83
127
  /**
84
128
  *
@@ -105,10 +149,8 @@ export class SerializeContext {
105
149
  let str = y + '-' + (m <= 9 ? '0' + m : m) + '-' + (d <= 9 ? '0' + d : d);
106
150
  /* istanbul ignore else */
107
151
  if (h + n + s)
108
- str += ' ' + (h <= 9 ? '0' + h : h) + ':' +
109
- (n <= 9 ? '0' + n : n) + ':' +
110
- (s <= 9 ? '0' + s : s);
111
- return '\'' + str + '\'';
152
+ str += ' ' + (h <= 9 ? '0' + h : h) + ':' + (n <= 9 ? '0' + n : n) + ':' + (s <= 9 ? '0' + s : s);
153
+ return "'" + str + "'";
112
154
  }
113
155
  /**
114
156
  * Check if a string value is a reserved word
@@ -26,7 +26,7 @@ export class CaseStatement extends Serializable {
26
26
  if (this._condition)
27
27
  this._expressions.push({
28
28
  condition: this._condition,
29
- value
29
+ value,
30
30
  });
31
31
  return this;
32
32
  }
@@ -56,13 +56,12 @@ export class CaseStatement extends Serializable {
56
56
  return '';
57
57
  const q = {
58
58
  expressions: [],
59
- elseValue: this._elseValue !== undefined ?
60
- ctx.anyToSQL(this._elseValue) : undefined
59
+ elseValue: this._elseValue !== undefined ? ctx.anyToSQL(this._elseValue) : undefined,
61
60
  };
62
61
  for (const x of this._expressions) {
63
62
  const o = {
64
63
  condition: x.condition._serialize(ctx),
65
- value: ctx.anyToSQL(x.value)
64
+ value: ctx.anyToSQL(x.value),
66
65
  };
67
66
  q.expressions.push(o);
68
67
  }
@@ -34,7 +34,6 @@ export class CoalesceStatement extends Serializable {
34
34
  return ctx.serialize(this._type, q, () => this.__defaultSerialize(ctx, q));
35
35
  }
36
36
  __defaultSerialize(ctx, o) {
37
- return 'coalesce(' + o.expressions.join(', ') + ')' +
38
- (this._alias ? ' ' + this._alias : '');
37
+ return 'coalesce(' + o.expressions.join(', ') + ')' + (this._alias ? ' ' + this._alias : '');
39
38
  }
40
39
  }
@@ -24,7 +24,9 @@ export class CountStatement extends Serializable {
24
24
  // noinspection JSUnusedLocalSymbols
25
25
  __defaultSerialize(
26
26
  /* eslint-disable-next-line */
27
- ctx, o) {
27
+ ctx,
28
+ /* eslint-disable-next-line */
29
+ o) {
28
30
  return 'count(*)';
29
31
  }
30
32
  }
@@ -36,14 +36,13 @@ export class FieldExpression extends BaseField {
36
36
  table: this._table,
37
37
  field: this._field,
38
38
  alias: this._alias,
39
- isReservedWord: !!(this._field && ctx.isReservedWord(this._field))
39
+ isReservedWord: !!(this._field && ctx.isReservedWord(this._field)),
40
40
  };
41
41
  return ctx.serialize(this._type, o, () => {
42
- const prefix = ctx.escapeReserved(this._schema ? this._schema + '.' : '') +
43
- (this._table ? this._table + '.' : '');
44
- return prefix +
42
+ const prefix = ctx.escapeReserved(this._schema ? this._schema + '.' : '') + (this._table ? this._table + '.' : '');
43
+ return (prefix +
45
44
  (!prefix && o.isReservedWord ? '"' + this._field + '"' : this._field) +
46
- (this._alias ? ' as ' + this._alias : '');
45
+ (this._alias ? ' as ' + this._alias : ''));
47
46
  });
48
47
  }
49
48
  }
@@ -23,12 +23,12 @@ export class GroupColumn extends BaseField {
23
23
  schema: this._schema,
24
24
  table: this._table,
25
25
  field: this._field,
26
- isReservedWord: !!(this._field && ctx.isReservedWord(this._field))
26
+ isReservedWord: !!(this._field && ctx.isReservedWord(this._field)),
27
27
  };
28
28
  return ctx.serialize(this._type, o, () => {
29
- return (this._schema ? this._schema + '.' : '') +
29
+ return ((this._schema ? this._schema + '.' : '') +
30
30
  (this._table ? this._table + '.' : '') +
31
- (o.isReservedWord ? '"' + this._field + '"' : this._field);
31
+ (o.isReservedWord ? '"' + this._field + '"' : this._field));
32
32
  });
33
33
  }
34
34
  }
@@ -8,8 +8,7 @@ export class JoinStatement extends Serializable {
8
8
  super();
9
9
  this._conditions = new OpAnd();
10
10
  // noinspection SuspiciousTypeOfGuard
11
- if (!(isSelectQuery(table) || isRawStatement(table) || isTableName(table) ||
12
- typeof table === 'string'))
11
+ if (!(isSelectQuery(table) || isRawStatement(table) || isTableName(table) || typeof table === 'string'))
13
12
  throw new TypeError('Table name, select query or raw object required for Join');
14
13
  this._joinType = joinType;
15
14
  this._table = typeof table === 'string' ? new TableName(table) : table;
@@ -25,7 +24,7 @@ export class JoinStatement extends Serializable {
25
24
  const o = {
26
25
  joinType: this._joinType,
27
26
  table: this._table._serialize(ctx),
28
- conditions: this.__serializeConditions(ctx, this)
27
+ conditions: this.__serializeConditions(ctx, this),
29
28
  };
30
29
  return ctx.serialize(this._type, o, () => {
31
30
  let out;
@@ -60,8 +59,7 @@ export class JoinStatement extends Serializable {
60
59
  const alias = this._table._alias;
61
60
  if (!alias)
62
61
  throw new Error('Alias required for sub-select in Join');
63
- out += ' (' + (lf ? '\n\t' : '') + o.table + (lf ? '\n\b' : '') + ')' +
64
- ' ' + alias;
62
+ out += ' (' + (lf ? '\n\t' : '') + o.table + (lf ? '\n\b' : '') + ')' + ' ' + alias;
65
63
  }
66
64
  else
67
65
  out += ' ' + o.table;
@@ -73,7 +71,7 @@ export class JoinStatement extends Serializable {
73
71
  __serializeConditions(ctx, join) {
74
72
  if (join._conditions._items.length) {
75
73
  const s = join._conditions._serialize(ctx);
76
- return ctx.serialize(SerializationType.JOIN_CONDITIONS, s, () => s ? 'on ' + s : '');
74
+ return ctx.serialize(SerializationType.JOIN_CONDITIONS, s, () => (s ? 'on ' + s : ''));
77
75
  }
78
76
  return '';
79
77
  }
@@ -29,7 +29,6 @@ export class LowerStatement extends Serializable {
29
29
  return ctx.serialize(this._type, q, () => this.__defaultSerialize(ctx, q));
30
30
  }
31
31
  __defaultSerialize(ctx, o) {
32
- return 'lower(' + o + ')' +
33
- (this._alias ? ' ' + this._alias : '');
32
+ return 'lower(' + o + ')' + (this._alias ? ' ' + this._alias : '');
34
33
  }
35
34
  }
@@ -29,7 +29,6 @@ export class MaxStatement extends Serializable {
29
29
  return ctx.serialize(this._type, q, () => this.__defaultSerialize(ctx, q));
30
30
  }
31
31
  __defaultSerialize(ctx, o) {
32
- return 'max(' + o + ')' +
33
- (this._alias ? ' ' + this._alias : '');
32
+ return 'max(' + o + ')' + (this._alias ? ' ' + this._alias : '');
34
33
  }
35
34
  }
@@ -29,7 +29,6 @@ export class MinStatement extends Serializable {
29
29
  return ctx.serialize(this._type, q, () => this.__defaultSerialize(ctx, q));
30
30
  }
31
31
  __defaultSerialize(ctx, o) {
32
- return 'min(' + o + ')' +
33
- (this._alias ? ' ' + this._alias : '');
32
+ return 'min(' + o + ')' + (this._alias ? ' ' + this._alias : '');
34
33
  }
35
34
  }
@@ -31,13 +31,12 @@ export class CompOperator extends Operator {
31
31
  operatorType: this._operatorType,
32
32
  symbol: this._symbol,
33
33
  left,
34
- right
34
+ right,
35
35
  };
36
36
  return this.__serialize(ctx, o);
37
37
  }
38
38
  __serializeItem(ctx, x, isRight) {
39
- if (ctx.strictParams && !(x instanceof Serializable) &&
40
- (typeof x !== 'string' || isRight)) {
39
+ if (ctx.strictParams && !(x instanceof Serializable) && (typeof x !== 'string' || isRight)) {
41
40
  ctx.strictParamGenId = ctx.strictParamGenId || 0;
42
41
  const name = 'P$_' + ++ctx.strictParamGenId;
43
42
  ctx.params = ctx.params || {};
@@ -47,7 +46,7 @@ export class CompOperator extends Operator {
47
46
  if (x instanceof Serializable) {
48
47
  const expression = ctx.anyToSQL(x);
49
48
  const result = {
50
- expression
49
+ expression,
51
50
  };
52
51
  if (x instanceof FieldExpression) {
53
52
  result.dataType = result._dataType;
@@ -65,8 +64,7 @@ export class CompOperator extends Operator {
65
64
  }
66
65
  else {
67
66
  const result = {
68
- expression: (isRight || typeof x !== 'string') ?
69
- ctx.anyToSQL(x) : x
67
+ expression: isRight || typeof x !== 'string' ? ctx.anyToSQL(x) : x,
70
68
  };
71
69
  if (isRight || typeof x !== 'string')
72
70
  result.isArray = Array.isArray(x);
@@ -46,7 +46,7 @@ export class LogicalOperator extends Operator {
46
46
  }
47
47
  return ctx.serialize(SerializationType.LOGICAL_EXPRESSION, arr, () => {
48
48
  const s = printArray(arr, ' ' + String(this._operatorType));
49
- return (s.indexOf('\n') > 0) ? s.replace('\n', '\n\t') + '\b' : s;
49
+ return s.indexOf('\n') > 0 ? s.replace('\n', '\n\t') + '\b' : s;
50
50
  });
51
51
  }
52
52
  // noinspection JSMethodCanBeStatic
@@ -12,20 +12,16 @@ export class OpBetween extends CompOperator {
12
12
  if (!(this._right && this._right.length > 0))
13
13
  return '';
14
14
  const left = this.__serializeItem(ctx, this._left);
15
- const right = [
16
- this.__serializeItem(ctx, this._right[0], true),
17
- this.__serializeItem(ctx, this._right[1], true)
18
- ];
15
+ const right = [this.__serializeItem(ctx, this._right[0], true), this.__serializeItem(ctx, this._right[1], true)];
19
16
  const o = {
20
17
  operatorType: this._operatorType,
21
18
  symbol: this._symbol,
22
19
  left,
23
- right
20
+ right,
24
21
  };
25
22
  return this.__serialize(ctx, o);
26
23
  }
27
24
  __defaultSerialize(ctx, o) {
28
- return o.left.expression + ' ' + o.symbol + ' ' +
29
- o.right[0].expression + ' and ' + o.right[1].expression;
25
+ return o.left.expression + ' ' + o.symbol + ' ' + o.right[0].expression + ' and ' + o.right[1].expression;
30
26
  }
31
27
  }
@@ -16,7 +16,7 @@ export class OpExists extends CompOperator {
16
16
  const o = {
17
17
  operatorType: this._operatorType,
18
18
  symbol: this._symbol,
19
- left
19
+ left,
20
20
  };
21
21
  return this.__serialize(ctx, o);
22
22
  }
@@ -14,7 +14,7 @@ export class OrderColumn extends BaseField {
14
14
  this._table = a.pop();
15
15
  this._schema = a.pop();
16
16
  }
17
- this._descending = !!((m[1] === '-') ||
17
+ this._descending = !!(m[1] === '-' ||
18
18
  (!m[1] && m[4] && ['dsc', 'desc', 'descending'].includes(m[4].toLowerCase())));
19
19
  }
20
20
  get _type() {
@@ -26,13 +26,13 @@ export class OrderColumn extends BaseField {
26
26
  table: this._table,
27
27
  field: this._field,
28
28
  descending: !!this._descending,
29
- isReservedWord: !!(this._field && ctx.isReservedWord(this._field))
29
+ isReservedWord: !!(this._field && ctx.isReservedWord(this._field)),
30
30
  };
31
31
  return ctx.serialize(this._type, o, () => {
32
- return (o.schema ? o.schema + '.' : '') +
32
+ return ((o.schema ? o.schema + '.' : '') +
33
33
  (o.table ? o.table + '.' : '') +
34
34
  (o.isReservedWord ? '"' + o.field + '"' : o.field) +
35
- (o.descending ? ' desc' : '');
35
+ (o.descending ? ' desc' : ''));
36
36
  });
37
37
  }
38
38
  }
@@ -38,8 +38,7 @@ export class ParamExpression extends Serializable {
38
38
  dataType: this._dataType,
39
39
  isArray: this._isArray,
40
40
  };
41
- ctx.paramOptions = ctx.paramOptions ||
42
- (Array.isArray(ctx.preparedParams) ? [] : {});
41
+ ctx.paramOptions = ctx.paramOptions || (Array.isArray(ctx.preparedParams) ? [] : {});
43
42
  if (Array.isArray(ctx.paramOptions))
44
43
  ctx.paramOptions.push(paramOps);
45
44
  else
@@ -16,13 +16,12 @@ export class ReturningColumn extends BaseField {
16
16
  _serialize(ctx) {
17
17
  const o = {
18
18
  field: this._field,
19
- alias: this._alias
19
+ alias: this._alias,
20
20
  };
21
21
  ctx.returningFields = ctx.returningFields || [];
22
22
  ctx.returningFields.push(o);
23
23
  return ctx.serialize(this._type, o, () => {
24
- return ctx.escapeReserved(o.field) +
25
- (o.alias ? ' as ' + ctx.escapeReserved(o.alias) : '');
24
+ return ctx.escapeReserved(o.field) + (o.alias ? ' as ' + ctx.escapeReserved(o.alias) : '');
26
25
  });
27
26
  }
28
27
  }
@@ -33,12 +33,11 @@ export class SequenceGetterStatement extends Serializable {
33
33
  const q = {
34
34
  genName: this._expression,
35
35
  next: this._next,
36
- alias: this._alias
36
+ alias: this._alias,
37
37
  };
38
38
  return ctx.serialize(this._type, q, () => this.__defaultSerialize(ctx, q));
39
39
  }
40
40
  __defaultSerialize(ctx, o) {
41
- return (o.next ? 'nextval' : 'currval') + '(\'' + o.genName + '\')' +
42
- (o.alias ? ' ' + o.alias : '');
41
+ return (o.next ? 'nextval' : 'currval') + "('" + o.genName + "')" + (o.alias ? ' ' + o.alias : '');
43
42
  }
44
43
  }