@sqb/builder 4.19.4 → 4.19.6

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 (40) hide show
  1. package/README.md +7 -7
  2. package/cjs/query/delete-query.js +4 -2
  3. package/cjs/query/insert-query.js +13 -4
  4. package/cjs/query/select-query.js +7 -2
  5. package/cjs/query/update-query.js +6 -3
  6. package/cjs/serialize-context.js +14 -3
  7. package/cjs/sql-objects/case-statement.js +3 -1
  8. package/cjs/sql-objects/coalesce-statement.js +4 -1
  9. package/cjs/sql-objects/field-expression.js +2 -1
  10. package/cjs/sql-objects/join-statement.js +12 -3
  11. package/cjs/sql-objects/operators/logical-operator.js +3 -1
  12. package/cjs/sql-objects/operators/op-between.js +11 -2
  13. package/cjs/sql-objects/operators/op-not.js +1 -1
  14. package/cjs/sql-objects/order-column.js +3 -1
  15. package/cjs/sql-objects/param-expression.js +2 -1
  16. package/cjs/sql-objects/returning-column.js +2 -1
  17. package/cjs/sql-objects/sequence-getter-statement.js +5 -1
  18. package/cjs/sql-objects/string-agg-statement.js +2 -1
  19. package/cjs/sql-objects/table-name.js +3 -1
  20. package/cjs/typeguards.js +17 -13
  21. package/esm/query/delete-query.js +4 -2
  22. package/esm/query/insert-query.js +14 -5
  23. package/esm/query/select-query.js +7 -2
  24. package/esm/query/update-query.js +6 -3
  25. package/esm/serialize-context.js +14 -3
  26. package/esm/sql-objects/case-statement.js +3 -1
  27. package/esm/sql-objects/coalesce-statement.js +4 -1
  28. package/esm/sql-objects/field-expression.js +2 -1
  29. package/esm/sql-objects/join-statement.js +12 -3
  30. package/esm/sql-objects/operators/logical-operator.js +4 -2
  31. package/esm/sql-objects/operators/op-between.js +11 -2
  32. package/esm/sql-objects/operators/op-not.js +1 -1
  33. package/esm/sql-objects/order-column.js +3 -1
  34. package/esm/sql-objects/param-expression.js +2 -1
  35. package/esm/sql-objects/returning-column.js +2 -1
  36. package/esm/sql-objects/sequence-getter-statement.js +5 -1
  37. package/esm/sql-objects/string-agg-statement.js +2 -1
  38. package/esm/sql-objects/table-name.js +3 -1
  39. package/esm/typeguards.js +17 -13
  40. package/package.json +6 -3
package/README.md CHANGED
@@ -18,12 +18,12 @@ SQB is an extensible, multi-dialect SQL query builder and Database connection wr
18
18
 
19
19
  ## Main goals
20
20
 
21
- - Single code base for any sql based database
22
- - Powerful and simplified query coding scheme
23
- - Fast applications with low memory requirements
24
- - Let applications work with large data tables efficiently
25
- - Support latest JavaScript language standards
26
- - Lightweight and extensible framework.
21
+ - Single code base for any sql based database
22
+ - Powerful and simplified query coding scheme
23
+ - Fast applications with low memory requirements
24
+ - Let applications work with large data tables efficiently
25
+ - Support latest JavaScript language standards
26
+ - Lightweight and extensible framework.
27
27
 
28
28
  You can report bugs and discuss features on the [GitHub issues](https://github.com/sqbjs/sqb/issues) page
29
29
 
@@ -39,7 +39,7 @@ $ npm install @sqb/builder --save
39
39
 
40
40
  ## Node Compatibility
41
41
 
42
- - node >= 16.x
42
+ - node >= 16.x
43
43
 
44
44
  ### License
45
45
 
@@ -9,10 +9,12 @@ const query_js_1 = require("./query.js");
9
9
  class DeleteQuery extends query_js_1.Query {
10
10
  constructor(tableName) {
11
11
  super();
12
- if (!tableName || !(typeof tableName === 'string' || (0, typeguards_js_1.isRawStatement)(tableName))) {
12
+ if (!tableName ||
13
+ !(typeof tableName === 'string' || (0, typeguards_js_1.isRawStatement)(tableName))) {
13
14
  throw new TypeError('String or Raw instance required as first argument (tableName) for UpdateQuery');
14
15
  }
15
- this._table = typeof tableName === 'string' ? new table_name_js_1.TableName(tableName) : tableName;
16
+ this._table =
17
+ typeof tableName === 'string' ? new table_name_js_1.TableName(tableName) : tableName;
16
18
  }
17
19
  get _type() {
18
20
  return enums_js_1.SerializationType.DELETE_QUERY;
@@ -9,13 +9,16 @@ const returning_query_js_1 = require("./returning-query.js");
9
9
  class InsertQuery extends returning_query_js_1.ReturningQuery {
10
10
  constructor(tableName, input) {
11
11
  super();
12
- if (!tableName || !(typeof tableName === 'string' || (0, typeguards_js_1.isRawStatement)(tableName))) {
12
+ if (!tableName ||
13
+ !(typeof tableName === 'string' || (0, typeguards_js_1.isRawStatement)(tableName))) {
13
14
  throw new TypeError('String or Raw instance required as first argument (tableName) for InsertQuery');
14
15
  }
15
- if (!input || !((typeof input === 'object' && !Array.isArray(input)) || input.isSelect)) {
16
+ if (!input ||
17
+ !((typeof input === 'object' && !Array.isArray(input)) || input.isSelect)) {
16
18
  throw new TypeError('Object or SelectQuery instance required as second argument (input) for InsertQuery');
17
19
  }
18
- this._table = typeof tableName === 'string' ? new table_name_js_1.TableName(tableName) : tableName;
20
+ this._table =
21
+ typeof tableName === 'string' ? new table_name_js_1.TableName(tableName) : tableName;
19
22
  this._input = input;
20
23
  }
21
24
  get _type() {
@@ -31,7 +34,13 @@ class InsertQuery extends returning_query_js_1.ReturningQuery {
31
34
  values: this.__serializeValues(ctx),
32
35
  returning: this.__serializeReturning(ctx),
33
36
  };
34
- let out = 'insert into ' + o.table + '\n\t(' + o.columns + ')\n\bvalues\n\t(' + o.values + ')\b';
37
+ let out = 'insert into ' +
38
+ o.table +
39
+ '\n\t(' +
40
+ o.columns +
41
+ ')\n\bvalues\n\t(' +
42
+ o.values +
43
+ ')\b';
35
44
  if (o.returning)
36
45
  out += '\n' + o.returning;
37
46
  return out;
@@ -151,11 +151,16 @@ class SelectQuery extends query_js_1.Query {
151
151
  // columns part
152
152
  /* istanbul ignore else */
153
153
  if (o.columns) {
154
- out += o.columns.indexOf('\n') >= 0 ? '\n\t' + o.columns + '\b' : ' ' + o.columns;
154
+ out +=
155
+ o.columns.indexOf('\n') >= 0
156
+ ? '\n\t' + o.columns + '\b'
157
+ : ' ' + o.columns;
155
158
  }
156
159
  // from part
157
160
  if (o.from) {
158
- out += (o.columns.length > 60 || o.columns.indexOf('\n') >= 0 ? '\n' : ' ') + o.from;
161
+ out +=
162
+ (o.columns.length > 60 || o.columns.indexOf('\n') >= 0 ? '\n' : ' ') +
163
+ o.from;
159
164
  }
160
165
  // join part
161
166
  if (o.join)
@@ -10,13 +10,16 @@ const returning_query_js_1 = require("./returning-query.js");
10
10
  class UpdateQuery extends returning_query_js_1.ReturningQuery {
11
11
  constructor(tableName, input) {
12
12
  super();
13
- if (!tableName || !(typeof tableName === 'string' || (0, typeguards_js_1.isRawStatement)(tableName))) {
13
+ if (!tableName ||
14
+ !(typeof tableName === 'string' || (0, typeguards_js_1.isRawStatement)(tableName))) {
14
15
  throw new TypeError('String or Raw instance required as first argument (tableName) for UpdateQuery');
15
16
  }
16
- if (!input || !((typeof input === 'object' && !Array.isArray(input)) || input.isSelect)) {
17
+ if (!input ||
18
+ !((typeof input === 'object' && !Array.isArray(input)) || input.isSelect)) {
17
19
  throw new TypeError('Object or Raw instance required as second argument (input) for UpdateQuery');
18
20
  }
19
- this._table = typeof tableName === 'string' ? new table_name_js_1.TableName(tableName) : tableName;
21
+ this._table =
22
+ typeof tableName === 'string' ? new table_name_js_1.TableName(tableName) : tableName;
20
23
  this._input = input;
21
24
  }
22
25
  get _type() {
@@ -96,12 +96,17 @@ class SerializeContext {
96
96
  return 'null';
97
97
  if (Array.isArray(v)) {
98
98
  const vv = v.map(x => this.anyToSQL(x));
99
- return this.serialize(enums_js_1.SerializationType.ARRAY, vv, () => '(' + vv.join(',')) + ')';
99
+ return (this.serialize(enums_js_1.SerializationType.ARRAY, vv, () => '(' + vv.join(',')) +
100
+ ')');
100
101
  }
101
102
  if (typeof v === 'object') {
102
103
  if ((0, typeguards_js_1.isSerializable)(v)) {
103
104
  const s = v._serialize(this);
104
- return s ? ((0, typeguards_js_1.isQuery)(v) || (0, typeguards_js_1.isLogicalOperator)(v) ? '(' + s + ')' : s) : /* istanbul ignore next */ '';
105
+ return s
106
+ ? (0, typeguards_js_1.isQuery)(v) || (0, typeguards_js_1.isLogicalOperator)(v)
107
+ ? '(' + s + ')'
108
+ : s
109
+ : /* istanbul ignore next */ '';
105
110
  }
106
111
  if (v instanceof Date) {
107
112
  return this.serialize(enums_js_1.SerializationType.DATE_VALUE, v, () => this.dateToSQL(v));
@@ -152,7 +157,13 @@ class SerializeContext {
152
157
  let str = y + '-' + (m <= 9 ? '0' + m : m) + '-' + (d <= 9 ? '0' + d : d);
153
158
  /* istanbul ignore else */
154
159
  if (h + n + s)
155
- str += ' ' + (h <= 9 ? '0' + h : h) + ':' + (n <= 9 ? '0' + n : n) + ':' + (s <= 9 ? '0' + s : s);
160
+ str +=
161
+ ' ' +
162
+ (h <= 9 ? '0' + h : h) +
163
+ ':' +
164
+ (n <= 9 ? '0' + n : n) +
165
+ ':' +
166
+ (s <= 9 ? '0' + s : s);
156
167
  return "'" + str + "'";
157
168
  }
158
169
  /**
@@ -60,7 +60,9 @@ class CaseStatement extends serializable_js_1.Serializable {
60
60
  return '';
61
61
  const q = {
62
62
  expressions: [],
63
- elseValue: this._elseValue !== undefined ? ctx.anyToSQL(this._elseValue) : undefined,
63
+ elseValue: this._elseValue !== undefined
64
+ ? ctx.anyToSQL(this._elseValue)
65
+ : undefined,
64
66
  };
65
67
  for (const x of this._expressions) {
66
68
  const o = {
@@ -37,7 +37,10 @@ class CoalesceStatement extends serializable_js_1.Serializable {
37
37
  return ctx.serialize(this._type, q, () => this.__defaultSerialize(ctx, q));
38
38
  }
39
39
  __defaultSerialize(ctx, o) {
40
- return 'coalesce(' + o.expressions.join(', ') + ')' + (this._alias ? ' ' + this._alias : '');
40
+ return ('coalesce(' +
41
+ o.expressions.join(', ') +
42
+ ')' +
43
+ (this._alias ? ' ' + this._alias : ''));
41
44
  }
42
45
  }
43
46
  exports.CoalesceStatement = CoalesceStatement;
@@ -42,7 +42,8 @@ class FieldExpression extends base_field_js_1.BaseField {
42
42
  isReservedWord: !!(this._field && ctx.isReservedWord(this._field)),
43
43
  };
44
44
  return ctx.serialize(this._type, o, () => {
45
- const prefix = ctx.escapeReserved(this._schema ? this._schema + '.' : '') + (this._table ? this._table + '.' : '');
45
+ const prefix = ctx.escapeReserved(this._schema ? this._schema + '.' : '') +
46
+ (this._table ? this._table + '.' : '');
46
47
  return (prefix +
47
48
  (!prefix && o.isReservedWord ? '"' + this._field + '"' : this._field) +
48
49
  (this._alias ? ' as ' + this._alias : ''));
@@ -11,7 +11,10 @@ class JoinStatement extends serializable_js_1.Serializable {
11
11
  super();
12
12
  this._conditions = new op_and_js_1.OpAnd();
13
13
  // noinspection SuspiciousTypeOfGuard
14
- if (!((0, typeguards_js_1.isSelectQuery)(table) || (0, typeguards_js_1.isRawStatement)(table) || (0, typeguards_js_1.isTableName)(table) || typeof table === 'string')) {
14
+ if (!((0, typeguards_js_1.isSelectQuery)(table) ||
15
+ (0, typeguards_js_1.isRawStatement)(table) ||
16
+ (0, typeguards_js_1.isTableName)(table) ||
17
+ typeof table === 'string')) {
15
18
  throw new TypeError('Table name, select query or raw object required for Join');
16
19
  }
17
20
  this._joinType = joinType;
@@ -63,7 +66,13 @@ class JoinStatement extends serializable_js_1.Serializable {
63
66
  const alias = this._table._alias;
64
67
  if (!alias)
65
68
  throw new Error('Alias required for sub-select in Join');
66
- out += ' (' + (lf ? '\n\t' : '') + o.table + (lf ? '\n\b' : '') + ') ' + alias;
69
+ out +=
70
+ ' (' +
71
+ (lf ? '\n\t' : '') +
72
+ o.table +
73
+ (lf ? '\n\b' : '') +
74
+ ') ' +
75
+ alias;
67
76
  }
68
77
  else
69
78
  out += ' ' + o.table;
@@ -75,7 +84,7 @@ class JoinStatement extends serializable_js_1.Serializable {
75
84
  __serializeConditions(ctx, join) {
76
85
  if (join._conditions._items.length) {
77
86
  const s = join._conditions._serialize(ctx);
78
- return ctx.serialize(enums_js_1.SerializationType.JOIN_CONDITIONS, s, () => (s ? 'on ' + s : ''));
87
+ return ctx.serialize(enums_js_1.SerializationType.JOIN_CONDITIONS, s, () => s ? 'on ' + s : '');
79
88
  }
80
89
  return '';
81
90
  }
@@ -29,7 +29,9 @@ class LogicalOperator extends operator_js_1.Operator {
29
29
  if ((0, typeguards_js_1.isLogicalOperator)(item)) {
30
30
  this._items.push(item);
31
31
  }
32
- else if ((0, typeguards_js_1.isRawStatement)(item) || (0, typeguards_js_1.isCompOperator)(item) || (0, typeguards_js_1.isNotOperator)(item)) {
32
+ else if ((0, typeguards_js_1.isRawStatement)(item) ||
33
+ (0, typeguards_js_1.isCompOperator)(item) ||
34
+ (0, typeguards_js_1.isNotOperator)(item)) {
33
35
  this._items.push(item);
34
36
  }
35
37
  else if ((0, putil_isplainobject_1.default)(item)) {
@@ -15,7 +15,10 @@ class OpBetween extends comp_operator_js_1.CompOperator {
15
15
  if (!(this._right && this._right.length > 0))
16
16
  return '';
17
17
  const left = this.__serializeItem(ctx, this._left);
18
- const right = [this.__serializeItem(ctx, this._right[0], true), this.__serializeItem(ctx, this._right[1], true)];
18
+ const right = [
19
+ this.__serializeItem(ctx, this._right[0], true),
20
+ this.__serializeItem(ctx, this._right[1], true),
21
+ ];
19
22
  const o = {
20
23
  operatorType: this._operatorType,
21
24
  symbol: this._symbol,
@@ -25,7 +28,13 @@ class OpBetween extends comp_operator_js_1.CompOperator {
25
28
  return this.__serialize(ctx, o);
26
29
  }
27
30
  __defaultSerialize(ctx, o) {
28
- return o.left.expression + ' ' + o.symbol + ' ' + o.right[0].expression + ' and ' + o.right[1].expression;
31
+ return (o.left.expression +
32
+ ' ' +
33
+ o.symbol +
34
+ ' ' +
35
+ o.right[0].expression +
36
+ ' and ' +
37
+ o.right[1].expression);
29
38
  }
30
39
  }
31
40
  exports.OpBetween = OpBetween;
@@ -14,7 +14,7 @@ class OpNot extends operator_js_1.Operator {
14
14
  }
15
15
  _serialize(ctx) {
16
16
  const expression = ctx.anyToSQL(this._expression);
17
- return ctx.serialize(this._type, expression, () => (expression ? 'not ' + expression : ''));
17
+ return ctx.serialize(this._type, expression, () => expression ? 'not ' + expression : '');
18
18
  }
19
19
  }
20
20
  exports.OpNot = OpNot;
@@ -18,7 +18,9 @@ class OrderColumn extends base_field_js_1.BaseField {
18
18
  this._schema = a.pop();
19
19
  }
20
20
  this._descending = !!(m[1] === '-' ||
21
- (!m[1] && m[4] && ['dsc', 'desc', 'descending'].includes(m[4].toLowerCase())));
21
+ (!m[1] &&
22
+ m[4] &&
23
+ ['dsc', 'desc', 'descending'].includes(m[4].toLowerCase())));
22
24
  }
23
25
  get _type() {
24
26
  return enums_js_1.SerializationType.ORDER_COLUMN;
@@ -41,7 +41,8 @@ class ParamExpression extends serializable_js_1.Serializable {
41
41
  dataType: this._dataType,
42
42
  isArray: this._isArray,
43
43
  };
44
- ctx.paramOptions = ctx.paramOptions || (Array.isArray(ctx.preparedParams) ? [] : {});
44
+ ctx.paramOptions =
45
+ ctx.paramOptions || (Array.isArray(ctx.preparedParams) ? [] : {});
45
46
  if (Array.isArray(ctx.paramOptions))
46
47
  ctx.paramOptions.push(paramOps);
47
48
  else
@@ -23,7 +23,8 @@ class ReturningColumn extends base_field_js_1.BaseField {
23
23
  };
24
24
  ctx.returningFields = ctx.returningFields || [];
25
25
  ctx.returningFields.push(o);
26
- return ctx.serialize(this._type, o, () => ctx.escapeReserved(o.field) + (o.alias ? ' as ' + ctx.escapeReserved(o.alias) : ''));
26
+ return ctx.serialize(this._type, o, () => ctx.escapeReserved(o.field) +
27
+ (o.alias ? ' as ' + ctx.escapeReserved(o.alias) : ''));
27
28
  }
28
29
  }
29
30
  exports.ReturningColumn = ReturningColumn;
@@ -41,7 +41,11 @@ class SequenceGetterStatement extends serializable_js_1.Serializable {
41
41
  return ctx.serialize(this._type, q, () => this.__defaultSerialize(ctx, q));
42
42
  }
43
43
  __defaultSerialize(ctx, o) {
44
- return (o.next ? 'nextval' : 'currval') + "('" + o.genName + "')" + (o.alias ? ' ' + o.alias : '');
44
+ return ((o.next ? 'nextval' : 'currval') +
45
+ "('" +
46
+ o.genName +
47
+ "')" +
48
+ (o.alias ? ' ' + o.alias : ''));
45
49
  }
46
50
  }
47
51
  exports.SequenceGetterStatement = SequenceGetterStatement;
@@ -9,7 +9,8 @@ const order_column_js_1 = require("./order-column.js");
9
9
  class StringAGGStatement extends serializable_js_1.Serializable {
10
10
  constructor(field, delimiter) {
11
11
  super();
12
- this._field = typeof field === 'string' ? new field_expression_js_1.FieldExpression(field) : field;
12
+ this._field =
13
+ typeof field === 'string' ? new field_expression_js_1.FieldExpression(field) : field;
13
14
  this._delimiter = delimiter || ',';
14
15
  }
15
16
  get _type() {
@@ -24,7 +24,9 @@ class TableName extends serializable_js_1.Serializable {
24
24
  schema: this.schema,
25
25
  table: this.table,
26
26
  alias: this.alias,
27
- }, () => (this.schema ? this.schema + '.' : '') + this.table + (this.alias ? ' ' + this.alias : ''));
27
+ }, () => (this.schema ? this.schema + '.' : '') +
28
+ this.table +
29
+ (this.alias ? ' ' + this.alias : ''));
28
30
  }
29
31
  }
30
32
  exports.TableName = TableName;
package/cjs/typeguards.js CHANGED
@@ -32,49 +32,53 @@ function isRawStatement(value) {
32
32
  return isSerializable(value) && value._type === enums_js_1.SerializationType.RAW;
33
33
  }
34
34
  function isSelectQuery(value) {
35
- return isSerializable(value) && value._type === enums_js_1.SerializationType.SELECT_QUERY;
35
+ return (isSerializable(value) && value._type === enums_js_1.SerializationType.SELECT_QUERY);
36
36
  }
37
37
  function isInsertQuery(value) {
38
- return isSerializable(value) && value._type === enums_js_1.SerializationType.INSERT_QUERY;
38
+ return (isSerializable(value) && value._type === enums_js_1.SerializationType.INSERT_QUERY);
39
39
  }
40
40
  function isIUpdateQuery(value) {
41
- return isSerializable(value) && value._type === enums_js_1.SerializationType.UPDATE_QUERY;
41
+ return (isSerializable(value) && value._type === enums_js_1.SerializationType.UPDATE_QUERY);
42
42
  }
43
43
  function isDeleteQuery(value) {
44
- return isSerializable(value) && value._type === enums_js_1.SerializationType.DELETE_QUERY;
44
+ return (isSerializable(value) && value._type === enums_js_1.SerializationType.DELETE_QUERY);
45
45
  }
46
46
  function isJoinStatement(value) {
47
47
  return isSerializable(value) && value._type === enums_js_1.SerializationType.JOIN;
48
48
  }
49
49
  function isCaseStatement(value) {
50
- return isSerializable(value) && value._type === enums_js_1.SerializationType.CASE_STATEMENT;
50
+ return (isSerializable(value) && value._type === enums_js_1.SerializationType.CASE_STATEMENT);
51
51
  }
52
52
  function isCountStatement(value) {
53
- return isSerializable(value) && value._type === enums_js_1.SerializationType.COUNT_STATEMENT;
53
+ return (isSerializable(value) && value._type === enums_js_1.SerializationType.COUNT_STATEMENT);
54
54
  }
55
55
  function isParamExpression(value) {
56
- return isSerializable(value) && value._type === enums_js_1.SerializationType.EXTERNAL_PARAMETER;
56
+ return (isSerializable(value) &&
57
+ value._type === enums_js_1.SerializationType.EXTERNAL_PARAMETER);
57
58
  }
58
59
  function isLogicalOperator(value) {
59
- return isSerializable(value) && value._type === enums_js_1.SerializationType.LOGICAL_EXPRESSION;
60
+ return (isSerializable(value) &&
61
+ value._type === enums_js_1.SerializationType.LOGICAL_EXPRESSION);
60
62
  }
61
63
  function isCompOperator(value) {
62
- return isSerializable(value) && value._type === enums_js_1.SerializationType.COMPARISON_EXPRESSION;
64
+ return (isSerializable(value) &&
65
+ value._type === enums_js_1.SerializationType.COMPARISON_EXPRESSION);
63
66
  }
64
67
  function isNotOperator(value) {
65
- return isSerializable(value) && value._type === enums_js_1.SerializationType.NEGATIVE_EXPRESSION;
68
+ return (isSerializable(value) &&
69
+ value._type === enums_js_1.SerializationType.NEGATIVE_EXPRESSION);
66
70
  }
67
71
  function isSelectColumn(value) {
68
72
  return isSerializable(value) && value._type === enums_js_1.SerializationType.FIELD_NAME;
69
73
  }
70
74
  function isOrderColumn(value) {
71
- return isSerializable(value) && value._type === enums_js_1.SerializationType.ORDER_COLUMN;
75
+ return (isSerializable(value) && value._type === enums_js_1.SerializationType.ORDER_COLUMN);
72
76
  }
73
77
  function isGroupColumn(value) {
74
- return isSerializable(value) && value._type === enums_js_1.SerializationType.GROUP_COLUMN;
78
+ return (isSerializable(value) && value._type === enums_js_1.SerializationType.GROUP_COLUMN);
75
79
  }
76
80
  function isReturningColumn(value) {
77
- return isSerializable(value) && value._type === enums_js_1.SerializationType.RETURNING_COLUMN;
81
+ return (isSerializable(value) && value._type === enums_js_1.SerializationType.RETURNING_COLUMN);
78
82
  }
79
83
  function isTableName(value) {
80
84
  return isSerializable(value) && value._type === enums_js_1.SerializationType.TABLE_NAME;
@@ -6,10 +6,12 @@ import { Query } from './query.js';
6
6
  export class DeleteQuery extends Query {
7
7
  constructor(tableName) {
8
8
  super();
9
- if (!tableName || !(typeof tableName === 'string' || isRawStatement(tableName))) {
9
+ if (!tableName ||
10
+ !(typeof tableName === 'string' || isRawStatement(tableName))) {
10
11
  throw new TypeError('String or Raw instance required as first argument (tableName) for UpdateQuery');
11
12
  }
12
- this._table = typeof tableName === 'string' ? new TableName(tableName) : tableName;
13
+ this._table =
14
+ typeof tableName === 'string' ? new TableName(tableName) : tableName;
13
15
  }
14
16
  get _type() {
15
17
  return SerializationType.DELETE_QUERY;
@@ -1,18 +1,21 @@
1
1
  import { SerializationType } from '../enums.js';
2
2
  import { printArray } from '../helpers.js';
3
3
  import { TableName } from '../sql-objects/table-name.js';
4
- import { isRawStatement, isSelectQuery, isSerializable } from '../typeguards.js';
4
+ import { isRawStatement, isSelectQuery, isSerializable, } from '../typeguards.js';
5
5
  import { ReturningQuery } from './returning-query.js';
6
6
  export class InsertQuery extends ReturningQuery {
7
7
  constructor(tableName, input) {
8
8
  super();
9
- if (!tableName || !(typeof tableName === 'string' || isRawStatement(tableName))) {
9
+ if (!tableName ||
10
+ !(typeof tableName === 'string' || isRawStatement(tableName))) {
10
11
  throw new TypeError('String or Raw instance required as first argument (tableName) for InsertQuery');
11
12
  }
12
- if (!input || !((typeof input === 'object' && !Array.isArray(input)) || input.isSelect)) {
13
+ if (!input ||
14
+ !((typeof input === 'object' && !Array.isArray(input)) || input.isSelect)) {
13
15
  throw new TypeError('Object or SelectQuery instance required as second argument (input) for InsertQuery');
14
16
  }
15
- this._table = typeof tableName === 'string' ? new TableName(tableName) : tableName;
17
+ this._table =
18
+ typeof tableName === 'string' ? new TableName(tableName) : tableName;
16
19
  this._input = input;
17
20
  }
18
21
  get _type() {
@@ -28,7 +31,13 @@ export class InsertQuery extends ReturningQuery {
28
31
  values: this.__serializeValues(ctx),
29
32
  returning: this.__serializeReturning(ctx),
30
33
  };
31
- let out = 'insert into ' + o.table + '\n\t(' + o.columns + ')\n\bvalues\n\t(' + o.values + ')\b';
34
+ let out = 'insert into ' +
35
+ o.table +
36
+ '\n\t(' +
37
+ o.columns +
38
+ ')\n\bvalues\n\t(' +
39
+ o.values +
40
+ ')\b';
32
41
  if (o.returning)
33
42
  out += '\n' + o.returning;
34
43
  return out;
@@ -148,11 +148,16 @@ 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 ? '\n\t' + o.columns + '\b' : ' ' + o.columns;
151
+ out +=
152
+ o.columns.indexOf('\n') >= 0
153
+ ? '\n\t' + o.columns + '\b'
154
+ : ' ' + o.columns;
152
155
  }
153
156
  // from part
154
157
  if (o.from) {
155
- out += (o.columns.length > 60 || o.columns.indexOf('\n') >= 0 ? '\n' : ' ') + o.from;
158
+ out +=
159
+ (o.columns.length > 60 || o.columns.indexOf('\n') >= 0 ? '\n' : ' ') +
160
+ o.from;
156
161
  }
157
162
  // join part
158
163
  if (o.join)
@@ -7,13 +7,16 @@ import { ReturningQuery } from './returning-query.js';
7
7
  export class UpdateQuery extends ReturningQuery {
8
8
  constructor(tableName, input) {
9
9
  super();
10
- if (!tableName || !(typeof tableName === 'string' || isRawStatement(tableName))) {
10
+ if (!tableName ||
11
+ !(typeof tableName === 'string' || isRawStatement(tableName))) {
11
12
  throw new TypeError('String or Raw instance required as first argument (tableName) for UpdateQuery');
12
13
  }
13
- if (!input || !((typeof input === 'object' && !Array.isArray(input)) || input.isSelect)) {
14
+ if (!input ||
15
+ !((typeof input === 'object' && !Array.isArray(input)) || input.isSelect)) {
14
16
  throw new TypeError('Object or Raw instance required as second argument (input) for UpdateQuery');
15
17
  }
16
- this._table = typeof tableName === 'string' ? new TableName(tableName) : tableName;
18
+ this._table =
19
+ typeof tableName === 'string' ? new TableName(tableName) : tableName;
17
20
  this._input = input;
18
21
  }
19
22
  get _type() {
@@ -93,12 +93,17 @@ export class SerializeContext {
93
93
  return 'null';
94
94
  if (Array.isArray(v)) {
95
95
  const vv = v.map(x => this.anyToSQL(x));
96
- return this.serialize(SerializationType.ARRAY, vv, () => '(' + vv.join(',')) + ')';
96
+ return (this.serialize(SerializationType.ARRAY, vv, () => '(' + vv.join(',')) +
97
+ ')');
97
98
  }
98
99
  if (typeof v === 'object') {
99
100
  if (isSerializable(v)) {
100
101
  const s = v._serialize(this);
101
- return s ? (isQuery(v) || isLogicalOperator(v) ? '(' + s + ')' : s) : /* istanbul ignore next */ '';
102
+ return s
103
+ ? isQuery(v) || isLogicalOperator(v)
104
+ ? '(' + s + ')'
105
+ : s
106
+ : /* istanbul ignore next */ '';
102
107
  }
103
108
  if (v instanceof Date) {
104
109
  return this.serialize(SerializationType.DATE_VALUE, v, () => this.dateToSQL(v));
@@ -149,7 +154,13 @@ export class SerializeContext {
149
154
  let str = y + '-' + (m <= 9 ? '0' + m : m) + '-' + (d <= 9 ? '0' + d : d);
150
155
  /* istanbul ignore else */
151
156
  if (h + n + s)
152
- str += ' ' + (h <= 9 ? '0' + h : h) + ':' + (n <= 9 ? '0' + n : n) + ':' + (s <= 9 ? '0' + s : s);
157
+ str +=
158
+ ' ' +
159
+ (h <= 9 ? '0' + h : h) +
160
+ ':' +
161
+ (n <= 9 ? '0' + n : n) +
162
+ ':' +
163
+ (s <= 9 ? '0' + s : s);
153
164
  return "'" + str + "'";
154
165
  }
155
166
  /**
@@ -57,7 +57,9 @@ export class CaseStatement extends Serializable {
57
57
  return '';
58
58
  const q = {
59
59
  expressions: [],
60
- elseValue: this._elseValue !== undefined ? ctx.anyToSQL(this._elseValue) : undefined,
60
+ elseValue: this._elseValue !== undefined
61
+ ? ctx.anyToSQL(this._elseValue)
62
+ : undefined,
61
63
  };
62
64
  for (const x of this._expressions) {
63
65
  const o = {
@@ -34,6 +34,9 @@ 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(', ') + ')' + (this._alias ? ' ' + this._alias : '');
37
+ return ('coalesce(' +
38
+ o.expressions.join(', ') +
39
+ ')' +
40
+ (this._alias ? ' ' + this._alias : ''));
38
41
  }
39
42
  }
@@ -39,7 +39,8 @@ export class FieldExpression extends BaseField {
39
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 + '.' : '') + (this._table ? this._table + '.' : '');
42
+ const prefix = ctx.escapeReserved(this._schema ? this._schema + '.' : '') +
43
+ (this._table ? this._table + '.' : '');
43
44
  return (prefix +
44
45
  (!prefix && o.isReservedWord ? '"' + this._field + '"' : this._field) +
45
46
  (this._alias ? ' as ' + this._alias : ''));
@@ -8,7 +8,10 @@ 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) || typeof table === 'string')) {
11
+ if (!(isSelectQuery(table) ||
12
+ isRawStatement(table) ||
13
+ isTableName(table) ||
14
+ typeof table === 'string')) {
12
15
  throw new TypeError('Table name, select query or raw object required for Join');
13
16
  }
14
17
  this._joinType = joinType;
@@ -60,7 +63,13 @@ export class JoinStatement extends Serializable {
60
63
  const alias = this._table._alias;
61
64
  if (!alias)
62
65
  throw new Error('Alias required for sub-select in Join');
63
- out += ' (' + (lf ? '\n\t' : '') + o.table + (lf ? '\n\b' : '') + ') ' + alias;
66
+ out +=
67
+ ' (' +
68
+ (lf ? '\n\t' : '') +
69
+ o.table +
70
+ (lf ? '\n\b' : '') +
71
+ ') ' +
72
+ alias;
64
73
  }
65
74
  else
66
75
  out += ' ' + o.table;
@@ -72,7 +81,7 @@ export class JoinStatement extends Serializable {
72
81
  __serializeConditions(ctx, join) {
73
82
  if (join._conditions._items.length) {
74
83
  const s = join._conditions._serialize(ctx);
75
- return ctx.serialize(SerializationType.JOIN_CONDITIONS, s, () => (s ? 'on ' + s : ''));
84
+ return ctx.serialize(SerializationType.JOIN_CONDITIONS, s, () => s ? 'on ' + s : '');
76
85
  }
77
86
  return '';
78
87
  }
@@ -1,7 +1,7 @@
1
1
  import isPlainObject from 'putil-isplainobject';
2
2
  import { SerializationType } from '../../enums.js';
3
3
  import { printArray } from '../../helpers.js';
4
- import { isCompOperator, isLogicalOperator, isNotOperator, isRawStatement } from '../../typeguards.js';
4
+ import { isCompOperator, isLogicalOperator, isNotOperator, isRawStatement, } from '../../typeguards.js';
5
5
  import { Operator } from '../operator.js';
6
6
  export const WrapOps = {};
7
7
  // noinspection RegExpUnnecessaryNonCapturingGroup
@@ -25,7 +25,9 @@ export class LogicalOperator extends Operator {
25
25
  if (isLogicalOperator(item)) {
26
26
  this._items.push(item);
27
27
  }
28
- else if (isRawStatement(item) || isCompOperator(item) || isNotOperator(item)) {
28
+ else if (isRawStatement(item) ||
29
+ isCompOperator(item) ||
30
+ isNotOperator(item)) {
29
31
  this._items.push(item);
30
32
  }
31
33
  else if (isPlainObject(item)) {
@@ -12,7 +12,10 @@ 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 = [this.__serializeItem(ctx, this._right[0], true), this.__serializeItem(ctx, this._right[1], true)];
15
+ const right = [
16
+ this.__serializeItem(ctx, this._right[0], true),
17
+ this.__serializeItem(ctx, this._right[1], true),
18
+ ];
16
19
  const o = {
17
20
  operatorType: this._operatorType,
18
21
  symbol: this._symbol,
@@ -22,6 +25,12 @@ export class OpBetween extends CompOperator {
22
25
  return this.__serialize(ctx, o);
23
26
  }
24
27
  __defaultSerialize(ctx, o) {
25
- return o.left.expression + ' ' + o.symbol + ' ' + o.right[0].expression + ' and ' + o.right[1].expression;
28
+ return (o.left.expression +
29
+ ' ' +
30
+ o.symbol +
31
+ ' ' +
32
+ o.right[0].expression +
33
+ ' and ' +
34
+ o.right[1].expression);
26
35
  }
27
36
  }
@@ -11,6 +11,6 @@ export class OpNot extends Operator {
11
11
  }
12
12
  _serialize(ctx) {
13
13
  const expression = ctx.anyToSQL(this._expression);
14
- return ctx.serialize(this._type, expression, () => (expression ? 'not ' + expression : ''));
14
+ return ctx.serialize(this._type, expression, () => expression ? 'not ' + expression : '');
15
15
  }
16
16
  }
@@ -15,7 +15,9 @@ export class OrderColumn extends BaseField {
15
15
  this._schema = a.pop();
16
16
  }
17
17
  this._descending = !!(m[1] === '-' ||
18
- (!m[1] && m[4] && ['dsc', 'desc', 'descending'].includes(m[4].toLowerCase())));
18
+ (!m[1] &&
19
+ m[4] &&
20
+ ['dsc', 'desc', 'descending'].includes(m[4].toLowerCase())));
19
21
  }
20
22
  get _type() {
21
23
  return SerializationType.ORDER_COLUMN;
@@ -38,7 +38,8 @@ export class ParamExpression extends Serializable {
38
38
  dataType: this._dataType,
39
39
  isArray: this._isArray,
40
40
  };
41
- ctx.paramOptions = ctx.paramOptions || (Array.isArray(ctx.preparedParams) ? [] : {});
41
+ ctx.paramOptions =
42
+ ctx.paramOptions || (Array.isArray(ctx.preparedParams) ? [] : {});
42
43
  if (Array.isArray(ctx.paramOptions))
43
44
  ctx.paramOptions.push(paramOps);
44
45
  else
@@ -20,6 +20,7 @@ export class ReturningColumn extends BaseField {
20
20
  };
21
21
  ctx.returningFields = ctx.returningFields || [];
22
22
  ctx.returningFields.push(o);
23
- return ctx.serialize(this._type, o, () => ctx.escapeReserved(o.field) + (o.alias ? ' as ' + ctx.escapeReserved(o.alias) : ''));
23
+ return ctx.serialize(this._type, o, () => ctx.escapeReserved(o.field) +
24
+ (o.alias ? ' as ' + ctx.escapeReserved(o.alias) : ''));
24
25
  }
25
26
  }
@@ -38,6 +38,10 @@ export class SequenceGetterStatement extends Serializable {
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 + "')" + (o.alias ? ' ' + o.alias : '');
41
+ return ((o.next ? 'nextval' : 'currval') +
42
+ "('" +
43
+ o.genName +
44
+ "')" +
45
+ (o.alias ? ' ' + o.alias : ''));
42
46
  }
43
47
  }
@@ -6,7 +6,8 @@ import { OrderColumn } from './order-column.js';
6
6
  export class StringAGGStatement extends Serializable {
7
7
  constructor(field, delimiter) {
8
8
  super();
9
- this._field = typeof field === 'string' ? new FieldExpression(field) : field;
9
+ this._field =
10
+ typeof field === 'string' ? new FieldExpression(field) : field;
10
11
  this._delimiter = delimiter || ',';
11
12
  }
12
13
  get _type() {
@@ -21,6 +21,8 @@ export class TableName extends Serializable {
21
21
  schema: this.schema,
22
22
  table: this.table,
23
23
  alias: this.alias,
24
- }, () => (this.schema ? this.schema + '.' : '') + this.table + (this.alias ? ' ' + this.alias : ''));
24
+ }, () => (this.schema ? this.schema + '.' : '') +
25
+ this.table +
26
+ (this.alias ? ' ' + this.alias : ''));
25
27
  }
26
28
  }
package/esm/typeguards.js CHANGED
@@ -11,49 +11,53 @@ export function isRawStatement(value) {
11
11
  return isSerializable(value) && value._type === SerializationType.RAW;
12
12
  }
13
13
  export function isSelectQuery(value) {
14
- return isSerializable(value) && value._type === SerializationType.SELECT_QUERY;
14
+ return (isSerializable(value) && value._type === SerializationType.SELECT_QUERY);
15
15
  }
16
16
  export function isInsertQuery(value) {
17
- return isSerializable(value) && value._type === SerializationType.INSERT_QUERY;
17
+ return (isSerializable(value) && value._type === SerializationType.INSERT_QUERY);
18
18
  }
19
19
  export function isIUpdateQuery(value) {
20
- return isSerializable(value) && value._type === SerializationType.UPDATE_QUERY;
20
+ return (isSerializable(value) && value._type === SerializationType.UPDATE_QUERY);
21
21
  }
22
22
  export function isDeleteQuery(value) {
23
- return isSerializable(value) && value._type === SerializationType.DELETE_QUERY;
23
+ return (isSerializable(value) && value._type === SerializationType.DELETE_QUERY);
24
24
  }
25
25
  export function isJoinStatement(value) {
26
26
  return isSerializable(value) && value._type === SerializationType.JOIN;
27
27
  }
28
28
  export function isCaseStatement(value) {
29
- return isSerializable(value) && value._type === SerializationType.CASE_STATEMENT;
29
+ return (isSerializable(value) && value._type === SerializationType.CASE_STATEMENT);
30
30
  }
31
31
  export function isCountStatement(value) {
32
- return isSerializable(value) && value._type === SerializationType.COUNT_STATEMENT;
32
+ return (isSerializable(value) && value._type === SerializationType.COUNT_STATEMENT);
33
33
  }
34
34
  export function isParamExpression(value) {
35
- return isSerializable(value) && value._type === SerializationType.EXTERNAL_PARAMETER;
35
+ return (isSerializable(value) &&
36
+ value._type === SerializationType.EXTERNAL_PARAMETER);
36
37
  }
37
38
  export function isLogicalOperator(value) {
38
- return isSerializable(value) && value._type === SerializationType.LOGICAL_EXPRESSION;
39
+ return (isSerializable(value) &&
40
+ value._type === SerializationType.LOGICAL_EXPRESSION);
39
41
  }
40
42
  export function isCompOperator(value) {
41
- return isSerializable(value) && value._type === SerializationType.COMPARISON_EXPRESSION;
43
+ return (isSerializable(value) &&
44
+ value._type === SerializationType.COMPARISON_EXPRESSION);
42
45
  }
43
46
  export function isNotOperator(value) {
44
- return isSerializable(value) && value._type === SerializationType.NEGATIVE_EXPRESSION;
47
+ return (isSerializable(value) &&
48
+ value._type === SerializationType.NEGATIVE_EXPRESSION);
45
49
  }
46
50
  export function isSelectColumn(value) {
47
51
  return isSerializable(value) && value._type === SerializationType.FIELD_NAME;
48
52
  }
49
53
  export function isOrderColumn(value) {
50
- return isSerializable(value) && value._type === SerializationType.ORDER_COLUMN;
54
+ return (isSerializable(value) && value._type === SerializationType.ORDER_COLUMN);
51
55
  }
52
56
  export function isGroupColumn(value) {
53
- return isSerializable(value) && value._type === SerializationType.GROUP_COLUMN;
57
+ return (isSerializable(value) && value._type === SerializationType.GROUP_COLUMN);
54
58
  }
55
59
  export function isReturningColumn(value) {
56
- return isSerializable(value) && value._type === SerializationType.RETURNING_COLUMN;
60
+ return (isSerializable(value) && value._type === SerializationType.RETURNING_COLUMN);
57
61
  }
58
62
  export function isTableName(value) {
59
63
  return isSerializable(value) && value._type === SerializationType.TABLE_NAME;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sqb/builder",
3
3
  "description": "Extensible multi-dialect SQL query builder written with TypeScript",
4
- "version": "4.19.4",
4
+ "version": "4.19.6",
5
5
  "author": "Panates",
6
6
  "license": "Apache-2.0",
7
7
  "dependencies": {
@@ -10,7 +10,7 @@
10
10
  "putil-isplainobject": "^1.1.5",
11
11
  "putil-merge": "^3.13.0",
12
12
  "putil-varhelpers": "^1.6.5",
13
- "tslib": "^2.8.0"
13
+ "tslib": "^2.8.1"
14
14
  },
15
15
  "type": "module",
16
16
  "exports": {
@@ -62,5 +62,8 @@
62
62
  "dialect",
63
63
  "multi-dialect",
64
64
  "database"
65
- ]
65
+ ],
66
+ "publishConfig": {
67
+ "access": "public"
68
+ }
66
69
  }