Skip to content

Commit

Permalink
Merge pull request #34 from kdhrubo/feature/33_support_like
Browse files Browse the repository at this point in the history
fixed #33
  • Loading branch information
kdhrubo authored Dec 20, 2023
2 parents d5a05fd + 2b0b772 commit cae6ed4
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 27 deletions.
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,21 @@ Instant REST API over your existing or new database in minutes.

#### Supported Operators

| Operator | Postgresql | Description | Supported |
|----------|----------------|-----------------------|-----------|
| == | = | equals | [X] |
| > | > | greater than | [X] |
| =gt= | > | greater than | [X] |
| >= | >= | greater than or equal | [X] |
| =gt= | > | greater than or equal | [X] |
| < | < | less than | [X] |
| =lt= | < | less than | [X] |
| <= | <= | less than or equal | [X] |
| =le= | <= | less than or equal | [X] |
| =in= | <= | in | [X] |
| =out= | <= | not in | [X] |
| Operator | Postgresql | Description | Supported |
|----------|------------|-----------------------|-----------|
| == | = | equals | [X] |
| > | > | greater than | [X] |
| =gt= | > | greater than | [X] |
| >= | >= | greater than or equal | [X] |
| =gt= | > | greater than or equal | [X] |
| < | < | less than | [X] |
| =lt= | < | less than | [X] |
| <= | <= | less than or equal | [X] |
| =le= | <= | less than or equal | [X] |
| =in= | <= | in | [X] |
| =out= | <= | not in | [X] |
| =like= | like | like | [X] |



### MySQL (Planned)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.homihq.db2rest.rsql;

import com.homihq.db2rest.rsql.operators.CustomRSQLOperators;
import com.homihq.db2rest.rsql.operators.handler.jooq.JooqCustomRSQLOperators;
import com.homihq.db2rest.rsql.parser.JooqRSQLVisitor;
import com.homihq.db2rest.schema.SchemaService;
import cz.jirutka.rsql.parser.RSQLParser;
Expand Down Expand Up @@ -32,7 +33,7 @@ public String getWhereClause(String tableName, String rSql) {
public void getWhereClause(SelectJoinStep<Record> selectFromStep, String tableName, String rSql) {
Table table = schemaService.getTableByName(tableName).orElseThrow();

Node rootNode = new RSQLParser().parse(rSql);
Node rootNode = new RSQLParser(JooqCustomRSQLOperators.customOperators()).parse(rSql);

log.info("root node - {}", rootNode);

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class RSQLOperatorHandlers {
static {


OPERATOR_HANDLER_MAP.put(LIKE.getSymbol(), new LikeOperatorHandler());

OPERATOR_HANDLER_MAP.put(START_WITH.getSymbol(), new StartWithOperatorHandler());
OPERATOR_HANDLER_MAP.put(END_WITH.getSymbol(), new EndWithOperatorHandler());

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.homihq.db2rest.rsql.operators.handler.jooq;

import cz.jirutka.rsql.parser.ast.ComparisonOperator;
import cz.jirutka.rsql.parser.ast.RSQLOperators;

import java.util.Arrays;
import java.util.Set;

public class JooqCustomRSQLOperators extends RSQLOperators {

public static final ComparisonOperator LIKE = new ComparisonOperator("=like=", false);
public static final ComparisonOperator START_WITH = new ComparisonOperator("=startWith=", false);
public static final ComparisonOperator END_WITH = new ComparisonOperator("=endWith=", false);

public static Set<ComparisonOperator> customOperators() {
Set<ComparisonOperator> comparisonOperators = defaultOperators();
comparisonOperators.addAll(Arrays.asList(LIKE, START_WITH, END_WITH));
return comparisonOperators;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.homihq.db2rest.rsql.operators.handler.jooq;

import com.homihq.db2rest.rsql.operators.handler.OperatorHandler;
import org.jooq.Condition;

import static org.jooq.impl.DSL.field;
import static org.jooq.impl.DSL.val;

public class JooqLikeOperatorHandler implements JooqOperatorHandler {

private static final String OPERATOR = " like ";

@Override
public Condition handle(String columnName, String value, Class type) {
//return columnName + OPERATOR + "'%" + value + "%'";
return
field(columnName)
.like(value);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class JooqRSQLOperatorHandlers {
OPERATOR_HANDLER_MAP.put(LESS_THAN.getSymbol(), new JooqLessThanOperatorHandler());
OPERATOR_HANDLER_MAP.put(LESS_THAN_OR_EQUAL.getSymbol(), new JooqLessThanEqualToOperatorHandler());
OPERATOR_HANDLER_MAP.put(NOT_EQUAL.getSymbol(), new JooqNotEqualToOperatorHandler());
OPERATOR_HANDLER_MAP.put(LIKE.getSymbol(), new JooqLikeOperatorHandler());
}

public static JooqOperatorHandler getOperatorHandler(String symbol) {
Expand Down

0 comments on commit cae6ed4

Please sign in to comment.