Skip to content

Commit dfa33d6

Browse files
committed
clear useless tablelist and column list in ast
1 parent 37eb3aa commit dfa33d6

3 files changed

Lines changed: 6 additions & 10 deletions

File tree

sql.pegjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@ crud_stmt
162162

163163
multiple_stmt
164164
= head:crud_stmt tail:(__ SEMICOLON __ crud_stmt)+ {
165-
const cur = [head];
165+
const cur = [head && head.ast || head];
166166
for (let i = 0; i < tail.length; i++) {
167167
if(!tail[i][3] || tail[i][3].length === 0) continue;
168-
cur.push(tail[i][3]);
168+
cur.push(tail[i][3] && tail[i][3].ast || tail[i][3]);
169169
}
170170
return {
171171
tableList: Array.from(tableList),

test/insert.spec.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@ describe('insert', () => {
3636
expect(tableList).to.eql(['insert::null::t1', 'select::null::t'])
3737
expect(columnList).to.eql([])
3838
expect(ast).to.have.lengthOf(2)
39-
expect(ast[0].tableList).to.eql(['insert::null::t1'])
40-
expect(ast[1].tableList).to.eql(['insert::null::t1', 'select::null::t'])
41-
expect(ast[0].ast).to.eql(astFirstSQL)
42-
expect(ast[1].ast).to.eql(astSecondSQL)
39+
expect(ast[0]).to.eql(astFirstSQL)
40+
expect(ast[1]).to.eql(astSecondSQL)
4341
})
4442

4543
it('failed with INSERT SELECT INFO', () => {

test/select.spec.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -693,10 +693,8 @@ describe('select', () => {
693693
const astFirstSQL = parser.sqlToAst(sqla.trim())
694694
const astSecondSQL = parser.sqlToAst(sqlb.trim())
695695
expect(ast).to.have.lengthOf(2)
696-
expect(ast[0].tableList).to.eql(['select::null::a'])
697-
expect(ast[1].tableList).to.eql(['select::null::a', 'select::null::b'])
698-
expect(ast[0].ast).to.eql(astFirstSQL)
699-
expect(ast[1].ast).to.eql(astSecondSQL)
696+
expect(ast[0]).to.eql(astFirstSQL)
697+
expect(ast[1]).to.eql(astSecondSQL)
700698
})
701699
})
702700

0 commit comments

Comments
 (0)