UNPKG

seamless-cloud

Version:

JavaScript client for Seamless.cloud (web and node)

34 lines 1.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sqlFormat = exports.sql = void 0; /** * SQL Tagged Template Literal * Format returned is compatible with running queries on Seamless.cloud */ function sql(strings, ...values) { let querySql = ''; let queryVars = {}; let index = 0; for (index = 0; index < values.length; index++) { const valueNumber = index + 1; const valuePlaceholder = '${' + valueNumber + '}'; const value = values[index]; queryVars[valueNumber] = value; querySql += strings[index] + valuePlaceholder; } querySql += strings[index]; return { querySql: sqlFormat(querySql), queryVars, }; } exports.sql = sql; /** * Format SQL string to remove all extra whitespace and linebreaks, etc. that are NOT inside quotes * Standardizes the SQL string for matching, logging, and hashing. */ function sqlFormat(sql) { return sql.replace(/\s+(?=(?:[^\'"]*[\'"][^\'"]*[\'"])*[^\'"]*$)/g, ' ').trim(); } exports.sqlFormat = sqlFormat; //# sourceMappingURL=sql.js.map