add RawValue

This commit is contained in:
开源海哥 2023-04-01 12:23:46 +08:00
parent 461300eaf7
commit 56c399725b
4 changed files with 70 additions and 1 deletions

View File

@ -151,6 +151,10 @@ public class QueryCondition implements Serializable {
else if (value instanceof QueryWrapper) {
sql.append("(").append(dialect.buildSelectSql((QueryWrapper) value)).append(")");
}
//原生sql
else if (value instanceof RawValue){
sql.append(((RawValue) value).getContext());
}
//正常查询构建问号
else {
appendQuestionMark(sql);
@ -180,7 +184,8 @@ public class QueryCondition implements Serializable {
if (LOGIC_IS_NULL.equals(logic)
|| LOGIC_IS_NOT_NULL.equals(logic)
|| value instanceof QueryColumn
|| value instanceof QueryWrapper) {
|| value instanceof QueryWrapper
|| value instanceof RawValue) {
//do nothing
}

View File

@ -95,4 +95,8 @@ public class QueryMethods {
return select(new StringQueryColumn("1"));
}
public static RawValue raw(String raw){
return new RawValue(raw);
}
}

View File

@ -0,0 +1,28 @@
package com.mybatisflex.core.query;
import java.io.Serializable;
public class RawValue implements Serializable {
private String context;
public RawValue() {
}
public RawValue(String context) {
this.context = context;
}
public String getContext() {
return context;
}
public void setContext(String context) {
this.context = context;
}
@Override
public String toString() {
return context;
}
}

View File

@ -226,6 +226,38 @@ public class AccountSqlTester {
System.out.println(sql);
}
@Test
public void testJoin2Sql() {
QueryWrapper queryWrapper = QueryWrapper.create()
.select()
.from(ACCOUNT)
.leftJoin(ARTICLE).on(
ACCOUNT.ID.eq(ARTICLE.ACCOUNT_ID).and(ACCOUNT.AGE.eq(18))
)
.where(ACCOUNT.AGE.ge(10));
IDialect dialect = new CommonsDialectImpl();
String sql = dialect.forSelectListByQuery(queryWrapper);
System.out.println(sql);
}
@Test
public void testJoin3Sql() {
QueryWrapper queryWrapper = QueryWrapper.create()
.select()
.from(ACCOUNT)
.leftJoin(
select().from(ARTICLE).where(ARTICLE.ID.ge(100))
).as("a").on(
ACCOUNT.ID.eq(raw("a.id"))
)
.where(ACCOUNT.AGE.ge(10));
IDialect dialect = new CommonsDialectImpl();
String sql = dialect.forSelectListByQuery(queryWrapper);
System.out.println(sql);
}
@Test
public void testOrderBySql() {
QueryWrapper queryWrapper = QueryWrapper.create()