Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
chore(pull): do not script comma out after the tvp's last column
Browse files Browse the repository at this point in the history
The comma after the last column is not allowed. It raises a syntax
error. Exception: `Incorrect syntax near ')'. `
  • Loading branch information
David Guilherme committed Apr 3, 2018
1 parent 3e861e5 commit 21f9f48
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/sql/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export function table(

// columns
for (const col of columns.filter(x => x.object_id === item.object_id)) {
output += ' ' + column(col);
output += ' ' + column(col) + ',';
output += EOL;
}

Expand Down Expand Up @@ -177,10 +177,18 @@ export function tvp(
output += EOL;

// columns
for (const col of columns.filter(x => x.object_id === item.object_id)) {
output += ' ' + column(col);
output += EOL;
}
columns
.filter(x => x.object_id === item.object_id)
.forEach((col, idx, array) => {
output += ' ' + column(col);

// if it is not the last column
if (idx !== array.length - 1) {
output += ',';
}

output += EOL;
});

output += ')';
output += EOL;
Expand Down Expand Up @@ -240,7 +248,6 @@ function column(item: ColumnRecordSet): string {
output += ` identity(${item.seed_value || 0}, ${item.increment_value || 1})`;
}

output += ',';
return output;
}

Expand Down

0 comments on commit 21f9f48

Please sign in to comment.