You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
523 B
JavaScript
20 lines
523 B
JavaScript
'use strict';
|
|
|
|
let insertRegex = /^insert into "[^"]+" \(([^\)]+)\)/;
|
|
let updateRegex = /^update "[^"]+" set (.+) where/;
|
|
let updateColumnRegex = /^"([^"]+)"/;
|
|
|
|
module.exports = function getColumns(query) {
|
|
let match;
|
|
|
|
if (match = insertRegex.exec(query)) {
|
|
return match[1].split(",").map((columnName) => {
|
|
return columnName.trim().slice(1, -1);
|
|
});
|
|
} else if (match = updateRegex.exec(query)) {
|
|
return match[1].split(",").map((statement) => {
|
|
return updateColumnRegex.exec(statement.trim())[1];
|
|
});
|
|
}
|
|
};
|