Skip to content

Commit

Permalink
Changed the way to create a query to make it more intuitive.
Browse files Browse the repository at this point in the history
Fixed an error in a property of the package.json file.
  • Loading branch information
sisimomo committed Nov 12, 2021
1 parent a35ecd9 commit 7b6868e
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 37 deletions.
60 changes: 30 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ A simple Query Builder for [Spring Filter](https://github.com/turkraft/spring-fi

Import index.js file in your javascript file:

```import * as SFQB from './src/index.js';```
```import { SpringFilterQueryBuilder as SFQB } from './src/index.js';```

Example:

```new SFQB.Or(new SFQB.And(new SFQB.Equal("test.test1", "testvalue1"), new SFQB.IsNotNull("test.test2"), ), new SFQB.NotEqual("test.test2", "testvalue2")).toString()```
```SFQB.or(SFQB.and(SFQB.equal("test.test1", "testvalue1"), SFQB.isNotNull("test.test2")), SFQB.notEqual("test.test2", "testvalue2")).toString()```

Enjoy!

Expand All @@ -20,37 +20,37 @@ All classes have a toString methode. So you can convert any Object of these clas
The library exposes all classes that you will need to create a query:

#### Operators
* **new SFQB.And(item, item ...)** - and's two or more expressions
* **new SFQB.Or(item, item ...)** - or's two or more expressions
* **new SFQB.Not(item)** - not's an expression
* **new SFQB.Exists(item)** - exists expression
* **SFQB.and(item, item ...)** - and's two or more expressions
* **SFQB.or(item, item ...)** - or's two or more expressions
* **SFQB.not(item)** - not's an expression
* **SFQB.exists(item)** - exists expression

#### Comparators
* **new SFQB.Like(selector, value)** - Like comparator
* **new SFQB.Equal(selector, value)** - Equal comparator
* **new SFQB.NotEqual(selector, value)** - Not equal comparator
* **new SFQB.Gt(selector, value)** - Greater than comparator
* **new SFQB.Ge(selector, value)** - Greater than or equal comparator
* **new SFQB.Lt(selector, value)** - Less than comparator
* **new SFQB.Le(selector, value)** - Less than or equal comparator
* **new SFQB.IsNull(selector)** - Is null comparator
* **new SFQB.IsNotNull(selector)** - Is not null comparator
* **new SFQB.IsEmpty(selector)** - Is empty comparator
* **new SFQB.IsNotEmpty(selector)** - Is not empty comparator
* **new SFQB.In(selector, value, value ...)** - In comparator
* **SFQB.like(selector, value)** - Like comparator
* **SFQB.equal(selector, value)** - Equal comparator
* **SFQB.notEqual(selector, value)** - Not equal comparator
* **SFQB.gt(selector, value)** - Greater than comparator
* **SFQB.ge(selector, value)** - Greater than or equal comparator
* **SFQB.lt(selector, value)** - Less than comparator
* **SFQB.le(selector, value)** - Less than or equal comparator
* **SFQB.isNull(selector)** - Is null comparator
* **SFQB.isNotNull(selector)** - Is not null comparator
* **SFQB.isEmpty(selector)** - Is empty comparator
* **SFQB.isNotEmpty(selector)** - Is not empty comparator
* **SFQB.in(selector, value, value ...)** - In comparator

PS: selector parameter must be either String or Function type

#### Functions
* **new SFQB.Absolute(selector)** - Absolute function
* **new SFQB.Average(selector)** - Average function
* **new SFQB.Min(selector)** - Min function
* **new SFQB.Max(selector)** - Max function
* **new SFQB.Sum(selector)** - Sum function
* **new SFQB.CurrentDate()** - CurrentDate function
* **new SFQB.CurrentTime()** - CurrentTime function
* **new SFQB.CurrentTimestamp()** - CurrentTimestamp function
* **new SFQB.Length(selector)** - Length function
* **new SFQB.Upper(selector)** - Upper function
* **new SFQB.Lower(selector)** - Lower function
* **new SFQB.Concat(selector)** - Concat function
* **SFQB.absolute(selector)** - Absolute function
* **SFQB.average(selector)** - Average function
* **SFQB.min(selector)** - Min function
* **SFQB.max(selector)** - Max function
* **SFQB.sum(selector)** - Sum function
* **SFQB.currentDate()** - CurrentDate function
* **SFQB.currentTime()** - CurrentTime function
* **SFQB.currentTimestamp()** - CurrentTimestamp function
* **SFQB.length(selector)** - Length function
* **SFQB.upper(selector)** - Upper function
* **SFQB.lower(selector)** - Lower function
* **SFQB.concat(selector)** - Concat function
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "spring-filter-query-builder",
"version": "0.2.0",
"version": "0.3.0",
"description": "A simple Query Builder for Spring Filter",
"main": "scr/index.js",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down
2 changes: 1 addition & 1 deletion src/comparators.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Comparator extends Item { //Abstract
}

toString() {
if (this.value) {
if (this.value != undefined) {
if (typeof this.value === 'number' || this.value instanceof Number) {
return `${this.selector} ${this.comparatorKeyWord} ${this.value}`;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Function extends Item { //Abstract
}

toString() {
if (this.selector) {
if (this.selector != undefined) {
return this.functionKeyWord + "(" + this.selector + ")";
} else {
return this.functionKeyWord + "()";
Expand Down
122 changes: 121 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,124 @@ import { Like, Equal, NotEqual, Gt, Ge, Lt, Le, IsNull, IsNotNull, IsEmpty, IsNo
import { And, Or, Not, Exists } from './operators.js';
import { Absolute, Average, Min, Max, Sum, CurrentDate, CurrentTime, CurrentTimestamp, Size, Length, Trim, Upper, Lower, Concat } from './functions.js';

export { Like, Equal, NotEqual, Gt, Ge, Lt, Le, IsNull, IsNotNull, IsEmpty, IsNotEmpty, In, And, Or, Not, Exists, Absolute, Average, Min, Max, Sum, CurrentDate, CurrentTime, CurrentTimestamp, Size, Length, Trim, Upper, Lower, Concat };
export class SpringFilterQueryBuilder {
static and(...items) {
return new And(...items);
}

static or(...items) {
return new Or(...items);
}

static not(item) {
return new Not(item);
}

static exists(item) {
return new Exists(...item);
}

static like(selector, value) {
return new Like(selector, value);
}

static equal(selector, value) {
return new Equal(selector, value);
}

static notEqual(selector, value) {
return new NotEqual(selector, value);
}

static gt(selector, value) {
return new Gt(selector, value);
}

static ge(selector, value) {
return new Ge(selector, value);
}

static lt(selector, value) {
return new Lt(selector, value);
}

static le(selector, value) {
return new Le(selector, value);
}

static isNull(selector, value) {
return new IsNull(selector, value);
}

static isNotNull(selector, value) {
return new IsNotNull(selector, value);
}

static isEmpty(selector, value) {
return new IsEmpty(selector, value);
}

static isNotEmpty(selector, value) {
return new IsNotEmpty(selector, value);
}

static in(selector, value) {
return new In(selector, value);
}

static absolute(selector) {
return new Absolute(selector);
}

static average(selector) {
return new Average(selector);
}

static min(selector) {
return new Min(selector);
}

static max(selector) {
return new Max(selector);
}

static sum(selector) {
return new Sum(selector);
}

static currentDate(selector) {
return new CurrentDate(selector);
}

static currentTime(selector) {
return new CurrentTime(selector);
}

static currentTimestamp(selector) {
return new CurrentTimestamp(selector);
}

static size(selector) {
return new Size(selector);
}

static length(selector) {
return new Length(selector);
}

static trim(selector) {
return new Trim(selector);
}

static upper(selector) {
return new Upper(selector);
}

static lower(selector) {
return new Lower(selector);
}

static concat(selector) {
return new Concat(selector);
}
}

0 comments on commit 7b6868e

Please sign in to comment.