UNPKG

sequelize

Version:

Sequelize is a promise-based Node.js ORM tool for Postgres, MySQL, MariaDB, SQLite, Microsoft SQL Server, Amazon Redshift and Snowflake’s Data Cloud. It features solid transaction support, relations, eager and lazy loading, read replication and more.

48 lines (47 loc) 1.34 kB
"use strict"; function doesNotWantLeadingSpace(str) { return /^[;,)]/.test(str); } function doesNotWantTrailingSpace(str) { return /\($/.test(str); } function singleSpaceJoinHelper(parts) { return parts.reduce(({ skipNextLeadingSpace, result }, part) => { if (skipNextLeadingSpace || doesNotWantLeadingSpace(part)) { result += part.trim(); } else { result += ` ${part.trim()}`; } return { skipNextLeadingSpace: doesNotWantTrailingSpace(part), result }; }, { skipNextLeadingSpace: true, result: "" }).result; } function joinSQLFragments(array) { if (array.length === 0) return ""; array = array.filter((x) => x); array = array.map((fragment) => { if (Array.isArray(fragment)) { return joinSQLFragments(fragment); } return fragment; }); for (const fragment of array) { if (fragment && typeof fragment !== "string") { const error = new TypeError(`Tried to construct a SQL string with a non-string, non-falsy fragment (${fragment}).`); error.args = array; error.fragment = fragment; throw error; } } array = array.map((x) => x.trim()); array = array.filter((x) => x !== ""); return singleSpaceJoinHelper(array); } exports.joinSQLFragments = joinSQLFragments; //# sourceMappingURL=join-sql-fragments.js.map