@brainnit/adonisjs-scout
Advanced tools
Comparing version 0.2.6 to 0.2.7
{ | ||
"name": "@brainnit/adonisjs-scout", | ||
"version": "0.2.6", | ||
"version": "0.2.7", | ||
"description": "Adonis Scout provides a driver based solution for searching your Lucid models, just like Laravel Scout.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -134,2 +134,4 @@ 'use strict' | ||
* | ||
* @chainable | ||
* | ||
* @param {Boolean} value | ||
@@ -170,3 +172,3 @@ * | ||
this._statements.push({ | ||
const stmt = { | ||
grouping: 'where', | ||
@@ -179,4 +181,18 @@ type: 'whereBasic', | ||
bool: this._bool() | ||
}) | ||
} | ||
/** | ||
* Mutates the statement if we are searching for something | ||
* "that is different than whatever" to apply the equal operator | ||
* and invert the `not` flag | ||
*/ | ||
if (['!=', '<>'].includes(operator)) { | ||
Object.assign(stmt, { | ||
operator: '=', | ||
not: !!stmt.not | ||
}) | ||
} | ||
this._statements.push(stmt) | ||
return this | ||
@@ -197,7 +213,36 @@ } | ||
orWhere () { | ||
this._bool('or') | ||
return this.where.apply(this, arguments) | ||
return this._bool('or').where.apply(this, arguments) | ||
} | ||
/** | ||
* Adds an `not where` clause to the query. | ||
* | ||
* @chainbale | ||
* | ||
* @param {String|Function} field | ||
* @param {String} operator | ||
* @param {*} value | ||
* | ||
* @return {Builder} this | ||
*/ | ||
whereNot () { | ||
return this._not(true).where.apply(this, arguments) | ||
} | ||
/** | ||
* Adds an `or not where` clause to the query. | ||
* | ||
* @chainbale | ||
* | ||
* @param {String|Function} field | ||
* @param {String} operator | ||
* @param {*} value | ||
* | ||
* @return {Builder} this | ||
*/ | ||
orWhereNot () { | ||
return this._bool('or').whereNot.apply(this, arguments) | ||
} | ||
/** | ||
* Adds an `advanced where` clause to the query. | ||
@@ -204,0 +249,0 @@ * |
@@ -28,3 +28,3 @@ 'use strict' | ||
const builder = new Builder(jest.fn(), 'query') | ||
builder.where('foo', 'match', 'bar') | ||
builder.where('foo', '=', 'bar') | ||
expect(builder._statements).toContainEqual({ | ||
@@ -34,3 +34,3 @@ grouping: 'where', | ||
field: 'foo', | ||
operator: 'match', | ||
operator: '=', | ||
value: 'bar', | ||
@@ -56,2 +56,44 @@ not: false, | ||
it('orWhere adds OR whereBasic statement', () => { | ||
const builder = new Builder(jest.fn(), 'query') | ||
builder.orWhere('foo', '=', 'bar') | ||
expect(builder._statements).toContainEqual({ | ||
grouping: 'where', | ||
type: 'whereBasic', | ||
field: 'foo', | ||
operator: '=', | ||
value: 'bar', | ||
not: false, | ||
bool: 'or' | ||
}) | ||
}) | ||
it('whereNot adds NOT whereBasic statement', () => { | ||
const builder = new Builder(jest.fn(), 'query') | ||
builder.whereNot('foo', '=', 'bar') | ||
expect(builder._statements).toContainEqual({ | ||
grouping: 'where', | ||
type: 'whereBasic', | ||
field: 'foo', | ||
operator: '=', | ||
value: 'bar', | ||
not: true, | ||
bool: 'and' | ||
}) | ||
}) | ||
it('orWhereNot adds OR NOT whereBasic statement', () => { | ||
const builder = new Builder(jest.fn(), 'query') | ||
builder.orWhereNot('foo', '=', 'bar') | ||
expect(builder._statements).toContainEqual({ | ||
grouping: 'where', | ||
type: 'whereBasic', | ||
field: 'foo', | ||
operator: '=', | ||
value: 'bar', | ||
not: true, | ||
bool: 'or' | ||
}) | ||
}) | ||
it('take changes limit', () => { | ||
@@ -58,0 +100,0 @@ const builder = new Builder(jest.fn(), 'query') |
150945
5184