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.
8 lines
11 KiB
8 lines
11 KiB
2 years ago
|
{
|
||
|
"version": 3,
|
||
|
"sources": ["../../src/utils/sql.ts"],
|
||
|
"sourcesContent": ["import isPlainObject from 'lodash/isPlainObject';\nimport type { AbstractDialect } from '../dialects/abstract/index.js';\nimport { escape as escapeSqlValue } from '../sql-string';\n\ntype BindOrReplacements = { [key: string]: unknown } | unknown[];\n\n/**\n * Inlines replacements in places where they would be valid SQL values.\n *\n * @param sqlString The SQL that contains the replacements\n * @param dialect The dialect of the SQL\n * @param replacements if provided, this method will replace ':named' replacements & positional replacements (?)\n *\n * @returns The SQL with replacements rewritten in their dialect-specific syntax.\n */\nexport function injectReplacements(\n sqlString: string,\n dialect: AbstractDialect,\n replacements: BindOrReplacements\n): string {\n if (replacements == null) {\n return sqlString;\n }\n\n if (!Array.isArray(replacements) && !isPlainObject(replacements)) {\n throw new TypeError(`\"replacements\" must be an array or a plain object, but received ${JSON.stringify(replacements)} instead.`);\n }\n\n const isNamedReplacements = isPlainObject(replacements);\n const isPositionalReplacements = Array.isArray(replacements);\n let lastConsumedPositionalReplacementIndex = -1;\n\n let output = '';\n\n let currentDollarStringTagName = null;\n let isString = false;\n let isColumn = false;\n let previousSliceEnd = 0;\n let isSingleLineComment = false;\n let isCommentBlock = false;\n let stringIsBackslashEscapable = false;\n\n for (let i = 0; i < sqlString.length; i++) {\n const char = sqlString[i];\n\n if (isColumn) {\n if (char === dialect.TICK_CHAR_RIGHT) {\n isColumn = false;\n }\n\n continue;\n }\n\n if (isString) {\n if (\n char === '\\'' &&\n (!stringIsBackslashEscapable || !isBackslashEscaped(sqlString, i - 1))\n ) {\n isString = false;\n stringIsBackslashEscapable = false;\n }\n\n continue;\n }\n\n if (currentDollarStringTagName !== null) {\n if (char !== '$') {\n continue;\n }\n\n const remainingString = sqlString.slice(i, sqlString.length);\n\n const dollarStringStartMatch = remainingString.match(/^\\$(?<name>[a-z_][0-9a-z_])?(\\$)/i);\n const tagName = dollarStringStartMatch?.groups?.name || '';\n if (currentDollarStringTagName === tagName) {\n currentDollarStringTagName = null;\n }\n\n continue;\n }\n\n if (isSingleLineComment) {\n if (char === '\\n') {\n isSingleLineComment = false;\n }\n\n continue;\n }\n\n if (isCommentBlock) {\n if (char === '*' && sqlString[i + 1] === '/') {\n isCommentBlock = false;\n }\n\n continue;\n }\n\n if (char === dialect.TICK_CHAR_LEFT) {\n isColumn = true;\n continue;\n }\n\n if (char === '\\'') {\n isString = true;\n\n // The following query is supported in almost all dialects,\n // SELECT E'test';\n // but postgres interprets it as an E-prefixed string, while other dialects interpret it as\n // SELECT E 'test';\n // which selects the type E and aliases it to 'test'.\n\n stringIsBackslashEscapable =\n // all ''-style strings in this dialect can be backslash escaped\n dialect.canBackslashEscape() ||\n // checking if this is a postgres-style E-prefixed string, which also supports backslash escaping\n dialect.supports.escapeStringConstants &&\n // is this a E-prefixed string, such as `E'abc'`, `e'abc'` ?\n (sqlString[i - 1] === 'E' || sqlString[i - 1] === 'e') &&\n // reject things such as `AE'abc'` (the prefix must be exactly E)\n canPrecedeNewToken(sqlString[i - 2]);\n\n continue;\n }\n\n if (char === '-' && sqlString.slice(i, i + 3) === '-- ') {\n isSingleLineComment = true;\n continue;\n }\n\n if (char === '/' && sqlString.slice(i, i + 2) === '/*') {\n isCommentBlock = true;\n continue;\n }\n\n // either the start of a $bind parameter, or the start of a $ta
|
||
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA,2BAA0B;AAE1B,wBAAyC;AAalC,4BACL,WACA,SACA,cACQ;AAnBV;AAoBE,MAAI,gBAAgB,MAAM;AACxB,WAAO;AAAA;AAGT,MAAI,CAAC,MAAM,QAAQ,iBAAiB,CAAC,kCAAc,eAAe;AAChE,UAAM,IAAI,UAAU,mEAAmE,KAAK,UAAU;AAAA;AAGxG,QAAM,sBAAsB,kCAAc;AAC1C,QAAM,2BAA2B,MAAM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