Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@databases/split-sql-query

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@databases/split-sql-query - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4-canary-2376

38

lib/__tests__/index.test.js

@@ -6,15 +6,15 @@ "use strict";

test('hasValues', () => {
expect(__1.hasValues(sql_1.default `SELECT * FROM ${sql_1.default.ident('my_table')}`)).toBe(false);
expect(__1.hasValues(sql_1.default `SELECT * FROM ${sql_1.default.ident('my_table')} WHERE id = ${42}`)).toBe(true);
expect((0, __1.hasValues)((0, sql_1.default) `SELECT * FROM ${sql_1.default.ident('my_table')}`)).toBe(false);
expect((0, __1.hasValues)((0, sql_1.default) `SELECT * FROM ${sql_1.default.ident('my_table')} WHERE id = ${42}`)).toBe(true);
});
test('hasSemicolonBeforeEnd', () => {
expect(__1.hasSemicolonBeforeEnd(sql_1.default `SELECT * FROM ${sql_1.default.ident('my_table')}`)).toBe(false);
expect(__1.hasSemicolonBeforeEnd(sql_1.default `SELECT * FROM ${sql_1.default.ident('my_table')} WHERE id = ${42};`)).toBe(false);
expect(__1.hasSemicolonBeforeEnd(sql_1.default `
expect((0, __1.hasSemicolonBeforeEnd)((0, sql_1.default) `SELECT * FROM ${sql_1.default.ident('my_table')}`)).toBe(false);
expect((0, __1.hasSemicolonBeforeEnd)((0, sql_1.default) `SELECT * FROM ${sql_1.default.ident('my_table')} WHERE id = ${42};`)).toBe(false);
expect((0, __1.hasSemicolonBeforeEnd)((0, sql_1.default) `
SELECT * FROM ${sql_1.default.ident('my_table')} WHERE id = ${42};
`)).toBe(false);
expect(__1.hasSemicolonBeforeEnd(sql_1.default `
expect((0, __1.hasSemicolonBeforeEnd)((0, sql_1.default) `
SELECT * FROM ${sql_1.default.ident('my_table')} WHERE val = ${'foo;bar'};
`)).toBe(false);
expect(__1.hasSemicolonBeforeEnd(sql_1.default `
expect((0, __1.hasSemicolonBeforeEnd)((0, sql_1.default) `
INSERT INTO ${sql_1.default.ident('my_table')} (id, value) VALUES (42, 'foo');

@@ -31,3 +31,3 @@ SELECT * FROM ${sql_1.default.ident('my_table')} WHERE id = ${42};

function doesNotSplit(query) {
const split = __1.default(query);
const split = (0, __1.default)(query);
expect(split.map((q) => q.format(testFormatter).text)).toEqual([

@@ -39,11 +39,11 @@ query.format(testFormatter).text,

test('splitSqlQuery', () => {
doesNotSplit(sql_1.default `SELECT * FROM ${sql_1.default.ident('my_table')}`);
doesNotSplit(sql_1.default `SELECT * FROM ${sql_1.default.ident('my_table')} WHERE id = ${42};`);
doesNotSplit(sql_1.default `
doesNotSplit((0, sql_1.default) `SELECT * FROM ${sql_1.default.ident('my_table')}`);
doesNotSplit((0, sql_1.default) `SELECT * FROM ${sql_1.default.ident('my_table')} WHERE id = ${42};`);
doesNotSplit((0, sql_1.default) `
SELECT * FROM ${sql_1.default.ident('my_table')} WHERE id = ${42};
`);
doesNotSplit(sql_1.default `
doesNotSplit((0, sql_1.default) `
SELECT * FROM ${sql_1.default.ident('my_table')} WHERE val = ${'foo;bar'};
`);
doesNotSplit(sql_1.default `
doesNotSplit((0, sql_1.default) `
SELECT * FROM ${sql_1.default.ident('my_table')} -- semicolons; in; comments; don't count;

@@ -53,12 +53,12 @@ WHERE val = 'foo;bar'

`);
expect(__1.default(sql_1.default `
expect((0, __1.default)((0, sql_1.default) `
INSERT INTO ${sql_1.default.ident('my_table')} (id, value) VALUES (42, 'foo');
SELECT * FROM ${sql_1.default.ident('my_table')} WHERE id = ${42};
`).map((q) => q.format(testFormatter))).toEqual([
sql_1.default `INSERT INTO ${sql_1.default.ident('my_table')} (id, value) VALUES (42, 'foo')`,
sql_1.default `SELECT * FROM ${sql_1.default.ident('my_table')} WHERE id = ${42}`,
(0, sql_1.default) `INSERT INTO ${sql_1.default.ident('my_table')} (id, value) VALUES (42, 'foo')`,
(0, sql_1.default) `SELECT * FROM ${sql_1.default.ident('my_table')} WHERE id = ${42}`,
].map((q) => q.format(testFormatter)));
});
test('regression - 1', () => {
expect(__1.default(sql_1.default `
expect((0, __1.default)((0, sql_1.default) `
CREATE DOMAIN custom_types.email AS TEXT CHECK (VALUE ~ '^.+@.+$');

@@ -87,3 +87,3 @@ CREATE TYPE custom_types.currency AS ENUM('USD', 'GBP');

test('regression - 2', () => {
expect(__1.default(sql_1.default `
expect((0, __1.default)((0, sql_1.default) `
CREATE OR REPLACE FUNCTION update_updated_at_column()

@@ -99,4 +99,4 @@ RETURNS TRIGGER AS $$

`).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);
expect((0, __1.default)((0, 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

@@ -213,2 +213,7 @@ "use strict";

exports.default = splitSqlQuery;
module.exports = Object.assign(splitSqlQuery, {
default: splitSqlQuery,
hasValues,
hasSemicolonBeforeEnd,
});
//# sourceMappingURL=index.js.map
{
"name": "@databases/split-sql-query",
"version": "1.0.3",
"version": "1.0.4-canary-2376",
"description": "",

@@ -8,3 +8,3 @@ "main": "./lib/index.js",

"devDependencies": {
"@databases/sql": "^3.1.0"
"@databases/sql": "3.3.0"
},

@@ -11,0 +11,0 @@ "peerDependencies": {

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc