You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
7 lines
6.0 KiB
7 lines
6.0 KiB
{ |
|
"version": 3, |
|
"sources": ["../src/sql-string.js"], |
|
"sourcesContent": ["'use strict';\n\nconst dataTypes = require('./data-types');\nconst { logger } = require('./utils/logger');\n\nfunction arrayToList(array, timeZone, dialect, format) {\n return array.reduce((sql, val, i) => {\n if (i !== 0) {\n sql += ', ';\n }\n if (Array.isArray(val)) {\n sql += `(${arrayToList(val, timeZone, dialect, format)})`;\n } else {\n sql += escape(val, timeZone, dialect, format);\n }\n return sql;\n }, '');\n}\nexports.arrayToList = arrayToList;\n\nfunction escape(val, timeZone, dialect, format) {\n let prependN = false;\n if (val === undefined || val === null) {\n return 'NULL';\n }\n switch (typeof val) {\n case 'boolean':\n // SQLite doesn't have true/false support. MySQL aliases true/false to 1/0\n // for us. Postgres actually has a boolean type with true/false literals,\n // but sequelize doesn't use it yet.\n if (['sqlite', 'mssql', 'oracle'].includes(dialect)) {\n return +!!val;\n }\n return (!!val).toString();\n case 'number':\n return val.toString();\n case 'string':\n // In mssql, prepend N to all quoted vals which are originally a string (for\n // unicode compatibility)\n prependN = dialect === 'mssql';\n break;\n }\n\n if (val instanceof Date) {\n val = dataTypes[dialect].DATE.prototype.stringify(val, { timezone: timeZone });\n }\n\n if (Buffer.isBuffer(val)) {\n if (dataTypes[dialect].BLOB) {\n return dataTypes[dialect].BLOB.prototype.stringify(val);\n }\n\n return dataTypes.BLOB.prototype.stringify(val);\n }\n\n if (Array.isArray(val)) {\n const partialEscape = escVal => escape(escVal, timeZone, dialect, format);\n if (dialect === 'postgres' && !format) {\n return dataTypes.ARRAY.prototype.stringify(val, { escape: partialEscape });\n }\n return arrayToList(val, timeZone, dialect, format);\n }\n\n if (!val.replace) {\n throw new Error(`Invalid value ${logger.inspect(val)}`);\n }\n\n if (['postgres', 'sqlite', 'mssql', 'snowflake', 'db2'].includes(dialect)) {\n // http://www.postgresql.org/docs/8.2/static/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS\n // http://stackoverflow.com/q/603572/130598\n val = val.replace(/'/g, \"''\");\n\n if (dialect === 'postgres') {\n // null character is not allowed in Postgres\n val = val.replace(/\\0/g, '\\\\0');\n }\n } else if (dialect === 'oracle' && typeof val === 'string') {\n if (val.startsWith('TO_TIMESTAMP') || val.startsWith('TO_DATE')) {\n return val;\n }\n val = val.replace(/'/g, \"''\");\n } else {\n\n // eslint-disable-next-line no-control-regex\n val = val.replace(/[\\0\\n\\r\\b\\t\\\\'\"\\x1a]/g, s => {\n switch (s) {\n case '\\0': return '\\\\0';\n case '\\n': return '\\\\n';\n case '\\r': return '\\\\r';\n case '\\b': return '\\\\b';\n case '\\t': return '\\\\t';\n case '\\x1a': return '\\\\Z';\n default: return `\\\\${s}`;\n }\n });\n }\n return `${(prependN ? \"N'\" : \"'\") + val}'`;\n}\nexports.escape = escape;\n\nfunction format(sql, values, timeZone, dialect) {\n values = [].concat(values);\n\n if (typeof sql !== 'string') {\n throw new Error(`Invalid SQL string provided: ${sql}`);\n }\n\n return sql.replace(/\\?/g, match => {\n if (!values.length) {\n return match;\n }\n\n return escape(values.shift(), timeZone, dialect, true);\n });\n}\nexports.format = format;\n\nfunction formatNamedParameters(sql, values, timeZone, dialect) {\n return sql.replace(/:+(?!\\d)(\\w+)/g, (value, key) => {\n if ('postgres' === dialect && '::' === value.slice(0, 2)) {\n return value;\n }\n\n if (values[key] !== undefined) {\n return escape(values[key], timeZone, dialect, true);\n }\n throw new Error(`Named parameter \"${value}\" has no value in the given object.`);\n });\n}\nexports.formatNamedParameters = formatNamedParameters;\n"], |
|
"mappings": ";AAEA,MAAM,YAAY,QAAQ;AAC1B,MAAM,EAAE,WAAW,QAAQ;AAE3B,qBAAqB,OAAO,UAAU,SAAS,SAAQ;AACrD,SAAO,MAAM,OAAO,CAAC,KAAK,KAAK,MAAM;AACnC,QAAI,MAAM,GAAG;AACX,aAAO;AAAA;AAET,QAAI,MAAM,QAAQ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