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

@balena/abstract-sql-compiler

Package Overview
Dependencies
Maintainers
4
Versions
467
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@balena/abstract-sql-compiler - npm Package Compare versions

Comparing version 7.6.0 to 7.7.0-empty-query-optimization-39431de07eeb98d731a114c1717575d364ddc06f

test/abstract-sql/empty-query-optimisations.ts

4

CHANGELOG.md

@@ -7,2 +7,6 @@ # Change Log

## 7.7.0 - 2021-01-01
* Optimize EXISTS/NOT EXISTS for empty queries [Pagan Gazzard]
## 7.6.0 - 2021-01-01

@@ -9,0 +13,0 @@

@@ -29,2 +29,19 @@ "use strict";

};
const isEmptySelectQuery = (query) => {
const [type, ...rest] = query;
switch (type) {
case 'SelectQuery':
for (const arg of rest) {
if (arg[0] === 'Where') {
const maybeBool = arg[1];
if (maybeBool[0] === 'Boolean') {
if (maybeBool[1] === false) {
return true;
}
}
}
}
}
return false;
};
const rewriteMatch = (name, matchers, rewriteFn) => (args) => {

@@ -793,5 +810,12 @@ checkArgs(name, args, matchers.length);

},
Exists: (args) => {
Exists: tryMatches(Helper((args) => {
checkArgs('Exists', args, 1);
const arg = getAbstractSqlQuery(args, 0);
if (isEmptySelectQuery(arg)) {
return ['Boolean', false];
}
return false;
}), (args) => {
checkArgs('Exists', args, 1);
const arg = getAbstractSqlQuery(args, 0);
const [type, ...rest] = arg;

@@ -805,4 +829,11 @@ switch (type) {

}
},
NotExists: (args) => {
}),
NotExists: tryMatches(Helper((args) => {
checkArgs('Exists', args, 1);
const arg = getAbstractSqlQuery(args, 0);
if (isEmptySelectQuery(arg)) {
return ['Boolean', true];
}
return false;
}), (args) => {
checkArgs('NotExists', args, 1);

@@ -818,3 +849,3 @@ const arg = getAbstractSqlQuery(args, 0);

}
},
}),
Not: tryMatches(Helper((args) => {

@@ -821,0 +852,0 @@ checkArgs('Not', args, 1);

2

package.json
{
"name": "@balena/abstract-sql-compiler",
"version": "7.6.0",
"version": "7.7.0-empty-query-optimization-39431de07eeb98d731a114c1717575d364ddc06f",
"description": "A translator for abstract sql into sql.",

@@ -5,0 +5,0 @@ "main": "out/AbstractSQLCompiler.js",

@@ -49,2 +49,20 @@ import * as _ from 'lodash';

const isEmptySelectQuery = (query: AbstractSqlQuery): boolean => {
const [type, ...rest] = query;
switch (type) {
case 'SelectQuery':
for (const arg of rest) {
if (arg[0] === 'Where') {
const maybeBool = arg[1];
if (maybeBool[0] === 'Boolean') {
if (maybeBool[1] === false) {
return true;
}
}
}
}
}
return false;
};
const rewriteMatch = (

@@ -918,26 +936,46 @@ name: string,

},
Exists: (args) => {
checkArgs('Exists', args, 1);
const arg = getAbstractSqlQuery(args, 0);
const [type, ...rest] = arg;
switch (type) {
case 'SelectQuery':
case 'UnionQuery':
return ['Exists', typeRules[type](rest)];
default:
return ['Exists', AnyValue(arg)];
}
},
NotExists: (args) => {
checkArgs('NotExists', args, 1);
const arg = getAbstractSqlQuery(args, 0);
const [type, ...rest] = arg;
switch (type) {
case 'SelectQuery':
case 'UnionQuery':
return ['NotExists', typeRules[type](rest)];
default:
return ['NotExists', AnyValue(arg)];
}
},
Exists: tryMatches(
Helper<OptimisationMatchFn>((args) => {
checkArgs('Exists', args, 1);
const arg = getAbstractSqlQuery(args, 0);
if (isEmptySelectQuery(arg)) {
return ['Boolean', false] as AbstractSqlQuery;
}
return false;
}),
(args) => {
checkArgs('Exists', args, 1);
const arg = getAbstractSqlQuery(args, 0);
const [type, ...rest] = arg;
switch (type) {
case 'SelectQuery':
case 'UnionQuery':
return ['Exists', typeRules[type](rest)];
default:
return ['Exists', AnyValue(arg)];
}
},
),
NotExists: tryMatches(
Helper<OptimisationMatchFn>((args) => {
checkArgs('Exists', args, 1);
const arg = getAbstractSqlQuery(args, 0);
if (isEmptySelectQuery(arg)) {
return ['Boolean', true] as AbstractSqlQuery;
}
return false;
}),
(args) => {
checkArgs('NotExists', args, 1);
const arg = getAbstractSqlQuery(args, 0);
const [type, ...rest] = arg;
switch (type) {
case 'SelectQuery':
case 'UnionQuery':
return ['NotExists', typeRules[type](rest)];
default:
return ['NotExists', AnyValue(arg)];
}
},
),
Not: tryMatches(

@@ -944,0 +982,0 @@ Helper<OptimisationMatchFn>((args) => {

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