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

the-query-builder

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

the-query-builder - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

dist/clauses/Union.d.ts

1

dist/clauses/index.d.ts

@@ -9,1 +9,2 @@ export { Select } from './Select';

export { Having } from './Having';
export { Union } from './Union';

4

dist/clauses/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Having = exports.OrderBy = exports.RawSQL = exports.JoinCondition = exports.Join = exports.Where = exports.From = exports.Select = void 0;
exports.Union = exports.Having = exports.OrderBy = exports.RawSQL = exports.JoinCondition = exports.Join = exports.Where = exports.From = exports.Select = void 0;
var Select_1 = require("./Select");

@@ -20,1 +20,3 @@ Object.defineProperty(exports, "Select", { enumerable: true, get: function () { return Select_1.Select; } });

Object.defineProperty(exports, "Having", { enumerable: true, get: function () { return Having_1.Having; } });
var Union_1 = require("./Union");
Object.defineProperty(exports, "Union", { enumerable: true, get: function () { return Union_1.Union; } });

@@ -1,2 +0,2 @@

import { From, RawSQL, Select, Where, OrderBy, Having } from './clauses';
import { From, RawSQL, Select, Where, OrderBy, Having, Union } from './clauses';
import { ColumnAlias, ComparisonOperators, LogicalOperators, QueryBuilderCallback, WhereQueryBuilderCallback, JoinQueryBuilderCallback, SortDirection, MathFunctions, QueryBuilder as QueryBuilderInterface } from '../types';

@@ -51,2 +51,4 @@ export default class QueryBuilder implements QueryBuilderInterface {

offset(offset: number): this;
union(...unions: QueryBuilder[]): this;
unionAll(...unions: QueryBuilder[]): this;
_isDistinct(): boolean;

@@ -62,3 +64,4 @@ _getSelects(): (Select | RawSQL)[];

_getOffset(): number | false;
_getUnions(): Union[];
getSQL(): string;
}

@@ -13,3 +13,3 @@ "use strict";

};
var _QueryBuilder_instances, _QueryBuilder_compiler, _QueryBuilder_selects, _QueryBuilder_tables, _QueryBuilder_wheres, _QueryBuilder_joins, _QueryBuilder_havings, _QueryBuilder_groupByColumns, _QueryBuilder_orderByColumns, _QueryBuilder_distinctSelect, _QueryBuilder_limitNumberRows, _QueryBuilder_offsetValue, _QueryBuilder_setWhere;
var _QueryBuilder_instances, _QueryBuilder_compiler, _QueryBuilder_selects, _QueryBuilder_tables, _QueryBuilder_wheres, _QueryBuilder_joins, _QueryBuilder_havings, _QueryBuilder_groupByColumns, _QueryBuilder_orderByColumns, _QueryBuilder_unions, _QueryBuilder_distinctSelect, _QueryBuilder_limitNumberRows, _QueryBuilder_offsetValue, _QueryBuilder_setWhere;
Object.defineProperty(exports, "__esModule", { value: true });

@@ -29,2 +29,3 @@ const clauses_1 = require("./clauses");

_QueryBuilder_orderByColumns.set(this, []);
_QueryBuilder_unions.set(this, []);
_QueryBuilder_distinctSelect.set(this, false);

@@ -203,2 +204,14 @@ _QueryBuilder_limitNumberRows.set(this, false);

}
union(...unions) {
unions.forEach(builder => {
__classPrivateFieldGet(this, _QueryBuilder_unions, "f").push(new clauses_1.Union(builder));
});
return this;
}
unionAll(...unions) {
unions.forEach(builder => {
__classPrivateFieldGet(this, _QueryBuilder_unions, "f").push(new clauses_1.Union(builder, true));
});
return this;
}
_isDistinct() {

@@ -234,2 +247,5 @@ return __classPrivateFieldGet(this, _QueryBuilder_distinctSelect, "f");

}
_getUnions() {
return __classPrivateFieldGet(this, _QueryBuilder_unions, "f");
}
getSQL() {

@@ -246,2 +262,3 @@ const sql = [

__classPrivateFieldGet(this, _QueryBuilder_compiler, "f").compileOffset(),
__classPrivateFieldGet(this, _QueryBuilder_compiler, "f").compileUnion()
];

@@ -255,3 +272,3 @@ return sql

exports.default = QueryBuilder;
_QueryBuilder_compiler = new WeakMap(), _QueryBuilder_selects = new WeakMap(), _QueryBuilder_tables = new WeakMap(), _QueryBuilder_wheres = new WeakMap(), _QueryBuilder_joins = new WeakMap(), _QueryBuilder_havings = new WeakMap(), _QueryBuilder_groupByColumns = new WeakMap(), _QueryBuilder_orderByColumns = new WeakMap(), _QueryBuilder_distinctSelect = new WeakMap(), _QueryBuilder_limitNumberRows = new WeakMap(), _QueryBuilder_offsetValue = new WeakMap(), _QueryBuilder_instances = new WeakSet(), _QueryBuilder_setWhere = function _QueryBuilder_setWhere(column, value, comparisonOperator, logicalOperator) {
_QueryBuilder_compiler = new WeakMap(), _QueryBuilder_selects = new WeakMap(), _QueryBuilder_tables = new WeakMap(), _QueryBuilder_wheres = new WeakMap(), _QueryBuilder_joins = new WeakMap(), _QueryBuilder_havings = new WeakMap(), _QueryBuilder_groupByColumns = new WeakMap(), _QueryBuilder_orderByColumns = new WeakMap(), _QueryBuilder_unions = new WeakMap(), _QueryBuilder_distinctSelect = new WeakMap(), _QueryBuilder_limitNumberRows = new WeakMap(), _QueryBuilder_offsetValue = new WeakMap(), _QueryBuilder_instances = new WeakSet(), _QueryBuilder_setWhere = function _QueryBuilder_setWhere(column, value, comparisonOperator, logicalOperator) {
// Nested where statement wrapped in parentheses

@@ -258,0 +275,0 @@ if (column instanceof Function) {

@@ -16,3 +16,4 @@ import { LogicalOperators } from '../types';

compileOffset(): string | null;
compileUnion(): string | null;
getOperator(operator: LogicalOperators | null): string;
}

@@ -201,2 +201,14 @@ "use strict";

}
compileUnion() {
let unions = [];
if (!__classPrivateFieldGet(this, _QueryCompiler_builder, "f")._getUnions().length) {
return null;
}
__classPrivateFieldGet(this, _QueryCompiler_builder, "f")
._getUnions()
.forEach((union) => {
unions.push((union.all ? 'UNION ALL ' : 'UNION ') + union.builder.getSQL());
});
return unions.join(' ');
}
getOperator(operator) {

@@ -203,0 +215,0 @@ return operator

{
"name": "the-query-builder",
"version": "1.0.0",
"version": "1.1.0",
"description": "SQL Query Builder",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -28,2 +28,4 @@ # Query Builder

- [Union](#union)
## Select

@@ -508,1 +510,60 @@

```
## Union
#### Available methods - union / unionAll
**Union**
```ts
const builder1 = (new QueryBuilder())
.select('something')
.from('table');
const sql = (new QueryBuilder())
.select('something_else')
.from('another_table')
.union(builder1)
.getSQL();
```
Generated SQL
```sql
SELECT something_else
FROM another_table
UNION
SELECT something
FROM table
```
**Union ALL**
```ts
const builder1 = (new QueryBuilder())
.select('something')
.from('table');
const builder2 = (new QueryBuilder())
.select('another_thing')
.from('another_table');
const sql = (new QueryBuilder())
.select('something_else')
.from('some_table')
.unionAll(builder1, builder2)
.getSQL();
```
Generated SQL
```sql
SELECT something_else
FROM some_table
UNION ALL
SELECT something
FROM table
UNION ALL
SELECT another_thing
FROM another_table
```

@@ -84,82 +84,2 @@ export type ColumnAlias = {

groupBy(column: string): QueryBuilder
getSQL(): string
}
interface WhereQueryBuilderInterface {
where(
column: string | WhereQueryBuilderCallback,
value?: string | number | QueryBuilderCallback | undefined,
comparisonOperator?: ComparisonOperators | LogicalOperators
): QueryBuilder
orWhere(
column: string | WhereQueryBuilderCallback,
value?: string | number | QueryBuilderCallback | null,
comparisonOperator?: ComparisonOperators | LogicalOperators
): QueryBuilder
whereLike(column: string, value: string): QueryBuilder
orWhereLike(column: string, value: string): QueryBuilder
whereNotLike(column: string, value: string): QueryBuilder
orWhereNotLike(column: string, value: string): QueryBuilder
whereBetween(
column: string,
min: string | number,
max: string | number
): QueryBuilder
whereNotBetween(
column: string,
min: string | number,
max: string | number
): QueryBuilder
orWhereBetween(
column: string,
min: string | number,
max: string | number
): QueryBuilder
orWhereNotBetween(
column: string,
min: string | number,
max: string | number
): QueryBuilder
whereIn(
column: string,
value: Array<string | number> | QueryBuilderCallback
): QueryBuilder
orWhereIn(
column: string,
value: Array<string | number> | QueryBuilderCallback
): QueryBuilder
whereNotIn(
column: string,
value: Array<string | number> | QueryBuilderCallback
): QueryBuilder
orWhereNotIn(
column: string,
value: Array<string | number> | QueryBuilderCallback
): QueryBuilder
whereIsNull(column: string): QueryBuilder
orWhereIsNull(column: string): QueryBuilder
whereIsNotNull(column: string): QueryBuilder
orWhereIsNotNull(column: string): QueryBuilder
whereRaw(sql: string, ...args: Array<string | number>): QueryBuilder
having(

@@ -248,4 +168,86 @@ column: string,

offset(offset: number): QueryBuilder
union(...unions: QueryBuilder[]): QueryBuilder
unionAll(...unions: QueryBuilder[]): QueryBuilder
getSQL(): string
}
interface WhereQueryBuilderInterface {
where(
column: string | WhereQueryBuilderCallback,
value?: string | number | QueryBuilderCallback | undefined,
comparisonOperator?: ComparisonOperators | LogicalOperators
): QueryBuilder
orWhere(
column: string | WhereQueryBuilderCallback,
value?: string | number | QueryBuilderCallback | null,
comparisonOperator?: ComparisonOperators | LogicalOperators
): QueryBuilder
whereLike(column: string, value: string): QueryBuilder
orWhereLike(column: string, value: string): QueryBuilder
whereNotLike(column: string, value: string): QueryBuilder
orWhereNotLike(column: string, value: string): QueryBuilder
whereBetween(
column: string,
min: string | number,
max: string | number
): QueryBuilder
whereNotBetween(
column: string,
min: string | number,
max: string | number
): QueryBuilder
orWhereBetween(
column: string,
min: string | number,
max: string | number
): QueryBuilder
orWhereNotBetween(
column: string,
min: string | number,
max: string | number
): QueryBuilder
whereIn(
column: string,
value: Array<string | number> | QueryBuilderCallback
): QueryBuilder
orWhereIn(
column: string,
value: Array<string | number> | QueryBuilderCallback
): QueryBuilder
whereNotIn(
column: string,
value: Array<string | number> | QueryBuilderCallback
): QueryBuilder
orWhereNotIn(
column: string,
value: Array<string | number> | QueryBuilderCallback
): QueryBuilder
whereIsNull(column: string): QueryBuilder
orWhereIsNull(column: string): QueryBuilder
whereIsNotNull(column: string): QueryBuilder
orWhereIsNotNull(column: string): QueryBuilder
whereRaw(sql: string, ...args: Array<string | number>): QueryBuilder
}
interface JoinQueryBuilderInterface {

@@ -252,0 +254,0 @@ on(

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