Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: knex/knex
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: splashlab/knex
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 1 commit
  • 3 files changed
  • 1 contributor

Commits on Apr 22, 2019

  1. Copy the full SHA
    07933f0 View commit details
Showing with 42 additions and 0 deletions.
  1. +26 −0 src/query/builder.js
  2. +1 −0 src/query/methods.js
  3. +15 −0 types/knex.d.ts
26 changes: 26 additions & 0 deletions src/query/builder.js
Original file line number Diff line number Diff line change
@@ -668,6 +668,32 @@ assign(Builder.prototype, {
return this;
},

// Adds an except statement to the query
except(callbacks, wrap) {
if (arguments.length === 1 || (arguments.length === 2 && isBoolean(wrap))) {
if (!Array.isArray(callbacks)) {
callbacks = [callbacks];
}
for (let i = 0, l = callbacks.length; i < l; i++) {
this._statements.push({
grouping: 'union',
clause: 'except',
value: callbacks[i],
wrap: wrap || false,
});
}
} else {
callbacks = toArray(arguments).slice(0, arguments.length - 1);
wrap = arguments[arguments.length - 1];
if (!isBoolean(wrap)) {
callbacks.push(wrap);
wrap = false;
}
this.except(callbacks, wrap);
}
return this;
},

// Adds a `having` clause to the query.
having(column, operator, value) {
if (column instanceof Raw && arguments.length === 1) {
1 change: 1 addition & 0 deletions src/query/methods.js
Original file line number Diff line number Diff line change
@@ -57,6 +57,7 @@ export default [
'union',
'unionAll',
'intersect',
'except',
'having',
'havingRaw',
'orHaving',
15 changes: 15 additions & 0 deletions types/knex.d.ts
Original file line number Diff line number Diff line change
@@ -139,6 +139,9 @@ declare namespace Knex {
// Intersect
intersect: Intersect;

// Except
except: Except;

// Union
union: Union;
unionAll: Union;
@@ -410,6 +413,18 @@ declare namespace Knex {
(...callbacks: (QueryCallback | QueryBuilder | Raw)[]): QueryBuilder;
}

interface Except {
(
callback: QueryCallback | QueryBuilder | Raw,
wrap?: boolean
): QueryBuilder;
(
callbacks: (QueryCallback | QueryBuilder | Raw)[],
wrap?: boolean
): QueryBuilder;
(...callbacks: (QueryCallback | QueryBuilder | Raw)[]): QueryBuilder;
}

interface Union {
(
callback: QueryCallback | QueryBuilder | Raw,