Skip to content

Commit 4adbc6a

Browse files
committed
Added 'mappedTo' to returnColumns for single column mapping
1 parent 848a8ee commit 4adbc6a

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

parser.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,20 @@ return {
309309
});
310310
let name;
311311
if(column.alias) name=column.alias.value;
312-
else name=column.expression;
312+
else name=this.toSql(column.expression);
313+
314+
let mappedTo;
315+
if(column.expression.type == 'identifier') {
316+
mappedTo = {column: column.expression.value};
317+
} else if (column.expression.type == 'column') {
318+
mappedTo = {column: column.expression.name, table: column.expression.table};
319+
}
320+
313321
returnColumns.push({
314322
name: name,
315-
sourceColumns: sourceColumns
323+
expression: column.expression,
324+
sourceColumns: sourceColumns,
325+
mappedTo
316326
});
317327
});
318328
}

test/test1.js

+19
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,25 @@ const tests = [
88
operation: 'select',
99
},
1010
toSql: '(select * from (`test`))'
11+
},{
12+
sql: 'select x from test',
13+
toSql: '(select `x` from (`test`))',
14+
expected: {
15+
returnColumns: [{
16+
expression: {
17+
type: 'identifier',
18+
value: 'x'
19+
},
20+
mappedTo: {
21+
column: 'x'
22+
},
23+
name: '`x`',
24+
sourceColumns: [{
25+
type: 'identifier',
26+
value: 'x'
27+
}]
28+
}]
29+
}
1130
},{
1231
sql: [
1332
'select * # comments!',

0 commit comments

Comments
 (0)