CartoDB-SQL-API/app/utils/query_info.js
2018-05-21 19:13:44 +02:00

22 lines
560 B
JavaScript

const COPY_FORMATS = ['TEXT', 'CSV', 'BINARY'];
module.exports = {
getFormatFromCopyQuery(copyQuery) {
let format = 'TEXT'; // Postgres default format
copyQuery = copyQuery.toUpperCase();
if (!copyQuery.toUpperCase().startsWith("COPY ")) {
return false;
}
const regex = /(\bFORMAT\s+)(\w+)/;
const result = regex.exec(copyQuery);
if (result && result.length >= 3 && COPY_FORMATS.includes(result[2])) {
format = result[2];
}
return format;
}
};