@@ -59,6 +59,8 @@ Sql.prototype.travelMain = function(ast) {
59
59
this . travelSelect ( ast . value ) ;
60
60
} else if ( ast . value . type === 'Update' ) {
61
61
this . travelUpdate ( ast . value ) ;
62
+ } else if ( ast . value . type === 'Insert' ) {
63
+ this . travelInsert ( ast . value ) ;
62
64
} else {
63
65
throw new Error ( 'Unknown query value type' ) ;
64
66
}
@@ -129,6 +131,64 @@ Sql.prototype.travelSelect = function(ast) {
129
131
this . appendKeyword ( ast . updateLockMode ) ;
130
132
}
131
133
}
134
+ Sql . prototype . travelInsert = function ( ast ) {
135
+ this . appendKeyword ( 'insert' , true ) ;
136
+
137
+ if ( ast . lowPriority ) {
138
+ this . appendKeyword ( 'low_priority' ) ;
139
+ }
140
+ if ( ast . ignore ) {
141
+ this . appendKeyword ( 'ignore' ) ;
142
+ }
143
+ if ( ast . into ) {
144
+ this . appendKeyword ( 'into' ) ;
145
+ }
146
+ this . travelTableRefrence ( ast . table ) ;
147
+ if ( ast . partitions ) {
148
+ this . travelPartitions ( ast . partitions ) ;
149
+ }
150
+ if ( ast . cols ) {
151
+ this . travel ( '(' ) ;
152
+ this . travelIdentifierList ( ast . cols ) ;
153
+ this . travel ( ')' ) ;
154
+ }
155
+ this . travel ( ast . value ) ;
156
+ if ( ast . src . type === 'Select' ) {
157
+ this . travelSelect ( ast . src ) ;
158
+ } else if ( ast . src . type === 'Values' ) {
159
+ this . travel ( ast . src . keyword ) ;
160
+ this . travelInsertRows ( ast . src . values ) ;
161
+ }
162
+ if ( ast . duplicateAssignments ) {
163
+ this . appendKeyword ( 'ON' ) ;
164
+ this . appendKeyword ( 'DUPLICATE' ) ;
165
+ this . appendKeyword ( 'KEY' ) ;
166
+ this . appendKeyword ( 'UPDATE' ) ;
167
+ this . travelAssignments ( ast . duplicateAssignments ) ;
168
+ }
169
+ }
170
+ Sql . prototype . travelInsertRows = function ( ast ) {
171
+ for ( var i = 0 ; i < ast . value . length ; i ++ ) {
172
+ var x = ast . value [ i ] ;
173
+ this . travel ( '(' ) ;
174
+ this . travelValueList ( x . value ) ;
175
+ this . travel ( ')' ) ;
176
+
177
+ if ( i !== ast . value . length - 1 ) {
178
+ this . append ( ',' , true ) ;
179
+ }
180
+ }
181
+ }
182
+ Sql . prototype . travelValueList = function ( ast ) {
183
+ for ( var i = 0 ; i < ast . length ; i ++ ) {
184
+ var x = ast [ i ] ;
185
+ this . travel ( x ) ;
186
+
187
+ if ( i !== ast . length - 1 ) {
188
+ this . append ( ',' , true ) ;
189
+ }
190
+ }
191
+ }
132
192
Sql . prototype . travelUpdate = function ( ast ) {
133
193
this . appendKeyword ( 'update' , true ) ;
134
194
if ( ast . lowPriority ) {
@@ -154,9 +214,9 @@ Sql.prototype.travelUpdate = function(ast) {
154
214
Sql . prototype . travelAssignments = function ( ast ) {
155
215
for ( var i = 0 ; i < ast . value . length ; i ++ ) {
156
216
var x = ast . value [ i ] ;
157
- this . travelIdentifier ( x . left ) ;
217
+ this . travel ( x . left ) ;
158
218
this . travel ( '=' ) ;
159
- this . travelIdentifier ( x . right ) ;
219
+ this . travel ( x . right ) ;
160
220
161
221
if ( i !== ast . value . length - 1 ) {
162
222
this . append ( ',' , true ) ;
0 commit comments