Skip to content

Commit dce2e59

Browse files
committed
feat(fixed and clause feature): added AND clause feature
provided AND clause feature to filter out from provided object
1 parent 1bc49c4 commit dce2e59

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

src/SelectQL.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ export class SelectQL implements ISelector {
2929
* @param expressionValue string or any value
3030
* @returns extracted array like object
3131
*/
32-
where(expressionKey: any, expressionOperator: Operators, expressionValue: any) : this {
32+
where(expressionKey: any, expressionOperator: Operators, expressionValue: any): this {
3333
let returned = this.data;
3434

3535
// checks if any of the where clause is key/operator or value is empty
3636
if (util.isEmpty(expressionKey) || util.isEmpty(expressionOperator) || util.isEmpty(expressionValue)) {
37-
throw new Error ('WHERE expression not provided correctly!');
37+
throw new Error('WHERE expression not provided correctly!');
3838
}
39-
39+
4040
if (expressionOperator == Operators.EQUAL) {
4141
// Returned only one item where condition met
4242
returned = this.data.splice(this.data.findIndex((o) => {
@@ -64,11 +64,11 @@ export class SelectQL implements ISelector {
6464
}
6565
}
6666

67-
/**
68-
* Creates a new array concatenating array with any additional arrays and/or values.
69-
* @param concatWith array or value
70-
* @returns this
71-
*/
67+
/**
68+
* Creates a new array concatenating array with any additional arrays and/or values.
69+
* @param concatWith array or value
70+
* @returns this
71+
*/
7272

7373
join(concatWith: any): this {
7474
this.data = !util.isEmpty(concatWith) ? this.data.concat(concatWith) : this;
@@ -83,15 +83,16 @@ export class SelectQL implements ISelector {
8383
* @returns extracted array like object
8484
*/
8585
and(expressionKey: any, expressionOperator: Operators, expressionValue: any): this {
86-
this.data = this.where(expressionKey, expressionOperator, expressionValue);
86+
let returnedAnd = this.where(expressionKey, expressionOperator, expressionValue);
87+
this.data = returnedAnd;
8788
return this;
8889
}
8990

90-
/**
91-
* Creates an array of unique values, taking an iteratee to compute uniqueness with the provided key
92-
* @param key string
93-
* @returns
94-
*/
91+
/**
92+
* Creates an array of unique values, taking an iteratee to compute uniqueness with the provided key
93+
* @param key string
94+
* @returns
95+
*/
9596
uniqueByKey(key: string): this {
9697
let uniquArr: any = [];
9798
this.data.forEach((value, index) => {
@@ -108,9 +109,11 @@ export class SelectQL implements ISelector {
108109
* @param input
109110
* @returns client's provided input.
110111
*/
111-
orElse(input: any): this {
112-
this.data = input;
113-
return this;
112+
ifEmptyThen(input: any): this {
113+
if (!this.data || util.isEmpty(this.data) || !this.data.length) {
114+
this.data = input
115+
}
116+
return this;
114117
}
115118

116119
/**

0 commit comments

Comments
 (0)