@@ -59,6 +59,8 @@ Sql.prototype.travelMain = function(ast) {
5959 this . travelSelect ( ast . value ) ;
6060 } else if ( ast . value . type === 'Update' ) {
6161 this . travelUpdate ( ast . value ) ;
62+ } else if ( ast . value . type === 'Insert' ) {
63+ this . travelInsert ( ast . value ) ;
6264 } else {
6365 throw new Error ( 'Unknown query value type' ) ;
6466 }
@@ -129,6 +131,64 @@ Sql.prototype.travelSelect = function(ast) {
129131 this . appendKeyword ( ast . updateLockMode ) ;
130132 }
131133}
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+ }
132192Sql . prototype . travelUpdate = function ( ast ) {
133193 this . appendKeyword ( 'update' , true ) ;
134194 if ( ast . lowPriority ) {
@@ -154,9 +214,9 @@ Sql.prototype.travelUpdate = function(ast) {
154214Sql . prototype . travelAssignments = function ( ast ) {
155215 for ( var i = 0 ; i < ast . value . length ; i ++ ) {
156216 var x = ast . value [ i ] ;
157- this . travelIdentifier ( x . left ) ;
217+ this . travel ( x . left ) ;
158218 this . travel ( '=' ) ;
159- this . travelIdentifier ( x . right ) ;
219+ this . travel ( x . right ) ;
160220
161221 if ( i !== ast . value . length - 1 ) {
162222 this . append ( ',' , true ) ;
0 commit comments