Skip to content

Commit

Permalink
feat: support like and not like operator
Browse files Browse the repository at this point in the history
  • Loading branch information
si3nloong committed Jan 22, 2020
1 parent 2ac2529 commit bf6caae
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 42 deletions.
15 changes: 13 additions & 2 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
import { filter, ne, or, eq, includes, notIncludes, gte, lte } from '../src';
import {
filter,
ne,
or,
eq,
includes,
notIncludes,
gte,
lte,
like,
} from '../src';

test('Query String', () => {
const qs = filter(
eq('name', 1),
ne('flag', true),
includes('status', ['A', 'B', 'C']),
notIncludes('status', ['A', 'B', 'C']),
like('test', 'xxx%'),
)
.sort('a', 'b', 'c')
.qs();
expect(qs).toBe(
`filter=(name==1;flag=ne=true;status=in=A,B,C;status=nin=A,B,C)&sort=a,b,c&limit=100`,
`filter=(name==1;flag=ne=true;status=in=A,B,C;status=nin=A,B,C;test=like='xxx%')&sort=a,b,c&limit=100`,
);

expect(filter(ne('b', 'value'), or(eq('c', 'v2'), eq('d', 'v4'))).qs()).toBe(
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rsql",
"version": "1.0.6",
"version": "1.0.7",
"description": "RSQL query string generator",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
6 changes: 6 additions & 0 deletions src/expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ export class Expression implements IStringer {
case Operator.NotIn:
str += '=nin=';
break;
case Operator.Like:
str += '=like=';
break;
case Operator.NotLike:
str += '=nlike=';
break;
default:
throw new Error('unsupported Operator');
}
Expand Down
40 changes: 1 addition & 39 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1 @@
import {
and,
eq,
filter,
gt,
gte,
includes,
like,
limit,
lt,
lte,
ne,
notIncludes,
notLike,
or,
select,
sort,
} from './query';

export {
and,
eq,
eq as equal,
filter,
gt,
gte,
includes,
like,
limit,
lt,
lte,
ne,
ne as notEqual,
notIncludes,
notLike,
or,
select,
sort,
};
export * from './query';

0 comments on commit bf6caae

Please sign in to comment.