dbgate-sqltree 5.3.3 → 5.4.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.
@@ -16,7 +16,7 @@ function dumpSqlSelect(dmp, cmd) {
16
16
  if (cmd.selectAll) {
17
17
  dmp.put('* ');
18
18
  }
19
- if (cmd.columns) {
19
+ if (cmd.columns && cmd.columns.length > 0) {
20
20
  if (cmd.selectAll)
21
21
  dmp.put('&n,');
22
22
  dmp.put('&>&n');
@@ -94,9 +94,21 @@ function dumpSqlDelete(dmp, cmd) {
94
94
  }
95
95
  exports.dumpSqlDelete = dumpSqlDelete;
96
96
  function dumpSqlInsert(dmp, cmd) {
97
- dmp.put('^insert ^into %f (%,i) ^values (', cmd.targetTable, cmd.fields.map(x => x.targetColumn));
98
- dmp.putCollection(',', cmd.fields, x => (0, dumpSqlExpression_1.dumpSqlExpression)(dmp, x));
99
- dmp.put(')');
97
+ if (cmd.insertWhereNotExistsCondition) {
98
+ dmp.put('^insert ^into %f (%,i) ^select ', cmd.targetTable, cmd.fields.map(x => x.targetColumn));
99
+ dmp.putCollection(',', cmd.fields, x => (0, dumpSqlExpression_1.dumpSqlExpression)(dmp, x));
100
+ if (dmp.dialect.requireFromDual) {
101
+ dmp.put(' ^from ^dual ');
102
+ }
103
+ dmp.put(' ^where ^not ^exists (^select * ^from %f ^where ', cmd.targetTable);
104
+ (0, dumpSqlCondition_1.dumpSqlCondition)(dmp, cmd.insertWhereNotExistsCondition);
105
+ dmp.put(')');
106
+ }
107
+ else {
108
+ dmp.put('^insert ^into %f (%,i) ^values (', cmd.targetTable, cmd.fields.map(x => x.targetColumn));
109
+ dmp.putCollection(',', cmd.fields, x => (0, dumpSqlExpression_1.dumpSqlExpression)(dmp, x));
110
+ dmp.put(')');
111
+ }
100
112
  }
101
113
  exports.dumpSqlInsert = dumpSqlInsert;
102
114
  function dumpSqlCommand(dmp, cmd) {
@@ -68,10 +68,17 @@ function dumpSqlCondition(dmp, condition) {
68
68
  dmp.put(' ^and ');
69
69
  (0, dumpSqlExpression_1.dumpSqlExpression)(dmp, condition.right);
70
70
  break;
71
+ case 'expression':
72
+ (0, dumpSqlExpression_1.dumpSqlExpression)(dmp, condition.expr);
73
+ break;
71
74
  case 'in':
72
75
  (0, dumpSqlExpression_1.dumpSqlExpression)(dmp, condition.expr);
73
76
  dmp.put(' ^in (%,v)', condition.values);
74
77
  break;
78
+ case 'notIn':
79
+ (0, dumpSqlExpression_1.dumpSqlExpression)(dmp, condition.expr);
80
+ dmp.put(' ^not ^in (%,v)', condition.values);
81
+ break;
75
82
  case 'rawTemplate':
76
83
  let was = false;
77
84
  for (const item of condition.templateSql.split('$$')) {
package/lib/types.d.ts CHANGED
@@ -30,6 +30,7 @@ export interface Insert {
30
30
  commandType: 'insert';
31
31
  fields: UpdateField[];
32
32
  targetTable: NamedObjectInfo;
33
+ insertWhereNotExistsCondition?: Condition;
33
34
  }
34
35
  export interface AllowIdentityInsert {
35
36
  commandType: 'allowIdentityInsert';
@@ -40,6 +41,9 @@ export type Command = Select | Update | Delete | Insert | AllowIdentityInsert;
40
41
  export interface UnaryCondition {
41
42
  expr: Expression;
42
43
  }
44
+ export interface ExpressionCondition extends UnaryCondition {
45
+ conditionType: 'expression';
46
+ }
43
47
  export interface BinaryCondition {
44
48
  conditionType: 'binary';
45
49
  operator: '=' | '!=' | '<>' | '<' | '>' | '>=' | '<=';
@@ -58,6 +62,10 @@ export interface NotCondition {
58
62
  export interface TestCondition extends UnaryCondition {
59
63
  conditionType: 'isNull' | 'isNotNull' | 'isEmpty' | 'isNotEmpty';
60
64
  }
65
+ export interface SpecificPredicateCondition extends UnaryCondition {
66
+ conditionType: 'specificPredicate';
67
+ predicate: string;
68
+ }
61
69
  export interface CompoudCondition {
62
70
  conditionType: 'and' | 'or';
63
71
  conditions: Condition[];
@@ -81,6 +89,11 @@ export interface InCondition {
81
89
  expr: Expression;
82
90
  values: any[];
83
91
  }
92
+ export interface NotInCondition {
93
+ conditionType: 'notIn';
94
+ expr: Expression;
95
+ values: any[];
96
+ }
84
97
  export interface RawTemplateCondition {
85
98
  conditionType: 'rawTemplate';
86
99
  templateSql: string;
@@ -90,7 +103,7 @@ export interface AnyColumnPassEvalOnlyCondition {
90
103
  conditionType: 'anyColumnPass';
91
104
  placeholderCondition: Condition;
92
105
  }
93
- export type Condition = BinaryCondition | NotCondition | TestCondition | CompoudCondition | LikeCondition | ExistsCondition | NotExistsCondition | BetweenCondition | InCondition | RawTemplateCondition | AnyColumnPassEvalOnlyCondition;
106
+ export type Condition = BinaryCondition | NotCondition | TestCondition | CompoudCondition | LikeCondition | ExistsCondition | NotExistsCondition | BetweenCondition | InCondition | NotInCondition | RawTemplateCondition | AnyColumnPassEvalOnlyCondition | SpecificPredicateCondition | ExpressionCondition;
94
107
  export interface Source {
95
108
  name?: NamedObjectInfo;
96
109
  alias?: string;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "5.3.3",
2
+ "version": "5.4.0",
3
3
  "name": "dbgate-sqltree",
4
4
  "main": "lib/index.js",
5
5
  "typings": "lib/index.d.ts",
@@ -27,7 +27,7 @@
27
27
  ],
28
28
  "devDependencies": {
29
29
  "@types/node": "^13.7.0",
30
- "dbgate-types": "^5.3.3",
30
+ "dbgate-types": "^5.4.0",
31
31
  "typescript": "^4.4.3"
32
32
  },
33
33
  "dependencies": {