@databases/split-sql-query
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -82,2 +82,16 @@ "use strict"; | ||
}); | ||
test('regression - 2', () => { | ||
expect(__1.default(sql_1.default ` | ||
CREATE OR REPLACE FUNCTION update_updated_at_column() | ||
RETURNS TRIGGER AS $$ | ||
BEGIN | ||
NEW.updated_at = now(); | ||
RETURN NEW; | ||
END; | ||
$$ language 'plpgsql'; | ||
CREATE TRIGGER <trigger_name> BEFORE UPDATE ON <table_name> FOR EACH ROW EXECUTE PROCEDURE update_updated_at_column(); | ||
`).length).toBe(2); | ||
expect(__1.default(sql_1.default `$SomeTag$Dianne's$WrongTag$;$some non tag an$identifier;; horse$SomeTag$;$SomeTag$Dianne's horse$SomeTag$`).length).toBe(2); | ||
}); | ||
//# sourceMappingURL=index.test.js.map |
@@ -50,2 +50,8 @@ "use strict"; | ||
let isBlockCommentEnd = false; | ||
// https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-DOLLAR-QUOTING | ||
// The tag, if any, of a dollar-quoted string follows the same rules as an unquoted identifier, | ||
// except that it cannot contain a dollar sign. Tags are case sensitive, so $tag$String content$tag$ | ||
// is correct, but $TAG$String content$tag$ is not. | ||
let dollarQuoteStart = ``; | ||
let dollarQuote = ``; | ||
for (const part of query) { | ||
@@ -74,2 +80,18 @@ if (part.type === web_1.SQLItemType.RAW) { | ||
} | ||
if (dollarQuoteStart && !dollarQuote) { | ||
if (char === `$`) { | ||
dollarQuote = `${dollarQuoteStart}$`; | ||
dollarQuoteStart = ``; | ||
str += char; | ||
continue; | ||
} | ||
else if (/[0-9_]/i.test(char) || | ||
// we allow letters with diacritical marks | ||
char.toLowerCase() !== char.toUpperCase()) { | ||
dollarQuoteStart += char; | ||
} | ||
else { | ||
dollarQuoteStart = ``; | ||
} | ||
} | ||
if (isBlockCommentFirstChar) { | ||
@@ -113,2 +135,15 @@ isBlockCommentFirstChar = false; | ||
} | ||
else if (dollarQuote) { | ||
if (dollarQuoteStart) { | ||
dollarQuoteStart += char; | ||
if (dollarQuoteStart === dollarQuote) { | ||
dollarQuote = ``; | ||
dollarQuoteStart = ``; | ||
} | ||
} | ||
if (dollarQuote && char === `$`) { | ||
dollarQuoteStart = `$`; | ||
} | ||
str += char; | ||
} | ||
else { | ||
@@ -122,2 +157,6 @@ switch (char) { | ||
break; | ||
case `$`: | ||
dollarQuoteStart = `$`; | ||
str += char; | ||
break; | ||
case `-`: | ||
@@ -124,0 +163,0 @@ lineCommentStart = true; |
{ | ||
"name": "@databases/split-sql-query", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
211185
323