Skip to content

Commit

Permalink
增加 eqSql 方法。 (#6029)
Browse files Browse the repository at this point in the history
Co-authored-by: Muyangmin <[email protected]>
  • Loading branch information
Muyangmin and Muyangmin authored Apr 5, 2024
1 parent 29e9705 commit 4162363
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,12 @@ public Children notIn(boolean condition, R column, Object... values) {
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), NOT_IN, inExpression(values)));
}

@Override
public Children eqSql(boolean condition, R column, String eqValue) {
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), EQ,
() -> String.format("(%s)", eqValue)));
}

@Override
public Children inSql(boolean condition, R column, String inValue) {
return maybeDo(condition, () -> appendSqlSegments(columnToSqlSegment(column), IN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,33 @@ default Children notIn(R column, Object... values) {
*/
Children notIn(boolean condition, R column, Object... values);

/**
* 字段 EQ ( sql语句 )
* <p>!! sql 注入方式的 eq 方法 !!</p>
* <p>例1: eqSql("id", "1")</p>
* <p>例2: eqSql("id", "select MAX(id) from table")</p>
*
* @param column 字段
* @param sql sql语句
* @return children
*/
default Children eqSql(R column, String sql) {
return eqSql(true, column, sql);
}

/**
* 字段 EQ ( sql语句 )
* <p>!! sql 注入方式的 eq 方法 !!</p>
* <p>例1: eqSql("id", "1")</p>
* <p>例2: eqSql("id", "select MAX(id) from table")</p>
*
* @param condition 执行条件
* @param column 字段
* @param sql sql语句
* @return children
*/
Children eqSql(boolean condition, R column, String sql);

/**
* 字段 IN ( sql语句 )
* <p>!! sql 注入方式的 in 方法 !!</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,13 @@ void testFunc() {
.groupBy("id").groupBy("name", "id2", "name2")
.in("inColl", getList()).or().notIn("notInColl", getList())
.in("inArray").notIn("notInArray", 5, 6, 7)
.eqSql("eqSql", "1")
.inSql("inSql", "1,2,3,4,5").notInSql("inSql", "1,2,3,4,5")
.gtSql("gtSql", "1,2,3,4,5").ltSql("ltSql", "1,2,3,4,5")
.geSql("geSql", "1,2,3,4,5").leSql("leSql", "1,2,3,4,5")
.having("sum(age) > {0}", 1).having("id is not null")
.func(entity.getId() != null, j -> j.eq("id", entity.getId()));// 不会npe,也不会加入sql
logSqlWhere("测试 Func 下的方法", queryWrapper, "(nullColumn IS NULL OR notNullColumn IS NOT NULL AND inColl IN (?,?) OR notInColl NOT IN (?,?) AND inArray IN () AND notInArray NOT IN (?,?,?) AND inSql IN (1,2,3,4,5) AND inSql NOT IN (1,2,3,4,5) AND gtSql > (1,2,3,4,5) AND ltSql < (1,2,3,4,5) AND geSql >= (1,2,3,4,5) AND leSql <= (1,2,3,4,5)) GROUP BY id,name,id2,name2 HAVING sum(age) > ? AND id is not null ORDER BY id ASC,name DESC,name2 DESC");
logSqlWhere("测试 Func 下的方法", queryWrapper, "(nullColumn IS NULL OR notNullColumn IS NOT NULL AND inColl IN (?,?) OR notInColl NOT IN (?,?) AND inArray IN () AND notInArray NOT IN (?,?,?) AND eqSql = (1) AND inSql IN (1,2,3,4,5) AND inSql NOT IN (1,2,3,4,5) AND gtSql > (1,2,3,4,5) AND ltSql < (1,2,3,4,5) AND geSql >= (1,2,3,4,5) AND leSql <= (1,2,3,4,5)) GROUP BY id,name,id2,name2 HAVING sum(age) > ? AND id is not null ORDER BY id ASC,name DESC,name2 DESC");
logParams(queryWrapper);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ public Children notIn(boolean condition, R column, Object... values) {
return typedThis;
}

@Override
public Children eqSql(boolean condition, R column, String eqValue) {
getWrapper().eqSql(condition, column, eqValue);
return typedThis;
}

@Override
public Children inSql(boolean condition, R column, String inValue) {
getWrapper().inSql(condition, column, inValue);
Expand Down

0 comments on commit 4162363

Please sign in to comment.